@emotion/hash
Advanced tools
Comparing version 0.7.4 to 0.8.0
# @emotion/hash | ||
## 0.8.0 | ||
### Minor Changes | ||
- [`446e756`](https://github.com/emotion-js/emotion/commit/446e75661c4aa01e51d1466472a212940c19cd82) [#1775](https://github.com/emotion-js/emotion/pull/1775) Thanks [@kripod](https://github.com/kripod)! - Optimized hashing for performance while also reducing the size of the function. | ||
## 0.7.4 | ||
@@ -4,0 +10,0 @@ |
@@ -6,20 +6,33 @@ 'use strict'; | ||
/* eslint-disable */ | ||
// murmurhash2 via https://github.com/garycourt/murmurhash-js/blob/master/murmurhash2_gc.js | ||
function murmurhash2_32_gc(str) { | ||
var l = str.length, | ||
h = l ^ l, | ||
// Inspired by https://github.com/garycourt/murmurhash-js | ||
// Ported from https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash2.cpp#L37-L86 | ||
function murmur2(str) { | ||
// 'm' and 'r' are mixing constants generated offline. | ||
// They're not really 'magic', they just happen to work well. | ||
// const m = 0x5bd1e995; | ||
// const r = 24; | ||
// Initialize the hash | ||
var h = 0; // Mix 4 bytes at a time into the hash | ||
var k, | ||
i = 0, | ||
k; | ||
len = str.length; | ||
while (l >= 4) { | ||
for (; len >= 4; ++i, len -= 4) { | ||
k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24; | ||
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
k ^= k >>> 24; | ||
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16) ^ k; | ||
l -= 4; | ||
++i; | ||
} | ||
k = | ||
/* Math.imul(k, m): */ | ||
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16); | ||
k ^= | ||
/* k >>> r: */ | ||
k >>> 24; | ||
h = | ||
/* Math.imul(k, m): */ | ||
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16) ^ | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
} // Handle the last few bytes of the input array | ||
switch (l) { | ||
switch (len) { | ||
case 3: | ||
@@ -33,11 +46,16 @@ h ^= (str.charCodeAt(i + 2) & 0xff) << 16; | ||
h ^= str.charCodeAt(i) & 0xff; | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
} | ||
h = | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
} // Do a few final mixes of the hash to ensure the last few | ||
// bytes are well-incorporated. | ||
h ^= h >>> 13; | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
h ^= h >>> 15; | ||
return (h >>> 0).toString(36); | ||
h = | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
return ((h ^ h >>> 15) >>> 0).toString(36); | ||
} | ||
exports.default = murmurhash2_32_gc; | ||
exports.default = murmur2; |
/* eslint-disable */ | ||
// murmurhash2 via https://github.com/garycourt/murmurhash-js/blob/master/murmurhash2_gc.js | ||
function murmurhash2_32_gc(str) { | ||
var l = str.length, | ||
h = l ^ l, | ||
// Inspired by https://github.com/garycourt/murmurhash-js | ||
// Ported from https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash2.cpp#L37-L86 | ||
function murmur2(str) { | ||
// 'm' and 'r' are mixing constants generated offline. | ||
// They're not really 'magic', they just happen to work well. | ||
// const m = 0x5bd1e995; | ||
// const r = 24; | ||
// Initialize the hash | ||
var h = 0; // Mix 4 bytes at a time into the hash | ||
var k, | ||
i = 0, | ||
k; | ||
len = str.length; | ||
while (l >= 4) { | ||
for (; len >= 4; ++i, len -= 4) { | ||
k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24; | ||
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
k ^= k >>> 24; | ||
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16) ^ k; | ||
l -= 4; | ||
++i; | ||
} | ||
k = | ||
/* Math.imul(k, m): */ | ||
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16); | ||
k ^= | ||
/* k >>> r: */ | ||
k >>> 24; | ||
h = | ||
/* Math.imul(k, m): */ | ||
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16) ^ | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
} // Handle the last few bytes of the input array | ||
switch (l) { | ||
switch (len) { | ||
case 3: | ||
@@ -28,11 +41,16 @@ h ^= (str.charCodeAt(i + 2) & 0xff) << 16; | ||
h ^= str.charCodeAt(i) & 0xff; | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
} | ||
h = | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
} // Do a few final mixes of the hash to ensure the last few | ||
// bytes are well-incorporated. | ||
h ^= h >>> 13; | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
h ^= h >>> 15; | ||
return (h >>> 0).toString(36); | ||
h = | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
return ((h ^ h >>> 15) >>> 0).toString(36); | ||
} | ||
export default murmurhash2_32_gc; | ||
export default murmur2; |
@@ -6,20 +6,33 @@ 'use strict'; | ||
/* eslint-disable */ | ||
// murmurhash2 via https://github.com/garycourt/murmurhash-js/blob/master/murmurhash2_gc.js | ||
function murmurhash2_32_gc(str) { | ||
var l = str.length, | ||
h = l ^ l, | ||
// Inspired by https://github.com/garycourt/murmurhash-js | ||
// Ported from https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash2.cpp#L37-L86 | ||
function murmur2(str) { | ||
// 'm' and 'r' are mixing constants generated offline. | ||
// They're not really 'magic', they just happen to work well. | ||
// const m = 0x5bd1e995; | ||
// const r = 24; | ||
// Initialize the hash | ||
var h = 0; // Mix 4 bytes at a time into the hash | ||
var k, | ||
i = 0, | ||
k; | ||
len = str.length; | ||
while (l >= 4) { | ||
for (; len >= 4; ++i, len -= 4) { | ||
k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24; | ||
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
k ^= k >>> 24; | ||
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16) ^ k; | ||
l -= 4; | ||
++i; | ||
} | ||
k = | ||
/* Math.imul(k, m): */ | ||
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16); | ||
k ^= | ||
/* k >>> r: */ | ||
k >>> 24; | ||
h = | ||
/* Math.imul(k, m): */ | ||
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16) ^ | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
} // Handle the last few bytes of the input array | ||
switch (l) { | ||
switch (len) { | ||
case 3: | ||
@@ -33,11 +46,16 @@ h ^= (str.charCodeAt(i + 2) & 0xff) << 16; | ||
h ^= str.charCodeAt(i) & 0xff; | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
} | ||
h = | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
} // Do a few final mixes of the hash to ensure the last few | ||
// bytes are well-incorporated. | ||
h ^= h >>> 13; | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
h ^= h >>> 15; | ||
return (h >>> 0).toString(36); | ||
h = | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
return ((h ^ h >>> 15) >>> 0).toString(36); | ||
} | ||
exports.default = murmurhash2_32_gc; | ||
exports.default = murmur2; |
"use strict"; | ||
function murmurhash2_32_gc(str) { | ||
for (var k, l = str.length, h = l ^ l, i = 0; l >= 4; ) k = 1540483477 * (65535 & (k = 255 & str.charCodeAt(i) | (255 & str.charCodeAt(++i)) << 8 | (255 & str.charCodeAt(++i)) << 16 | (255 & str.charCodeAt(++i)) << 24)) + ((1540483477 * (k >>> 16) & 65535) << 16), | ||
h = 1540483477 * (65535 & h) + ((1540483477 * (h >>> 16) & 65535) << 16) ^ (k = 1540483477 * (65535 & (k ^= k >>> 24)) + ((1540483477 * (k >>> 16) & 65535) << 16)), | ||
l -= 4, ++i; | ||
switch (l) { | ||
function murmur2(str) { | ||
for (var k, h = 0, i = 0, len = str.length; len >= 4; ++i, len -= 4) k = 1540483477 * (65535 & (k = 255 & str.charCodeAt(i) | (255 & str.charCodeAt(++i)) << 8 | (255 & str.charCodeAt(++i)) << 16 | (255 & str.charCodeAt(++i)) << 24)) + (59797 * (k >>> 16) << 16), | ||
h = 1540483477 * (65535 & (k ^= k >>> 24)) + (59797 * (k >>> 16) << 16) ^ 1540483477 * (65535 & h) + (59797 * (h >>> 16) << 16); | ||
switch (len) { | ||
case 3: | ||
@@ -15,6 +14,5 @@ h ^= (255 & str.charCodeAt(i + 2)) << 16; | ||
case 1: | ||
h = 1540483477 * (65535 & (h ^= 255 & str.charCodeAt(i))) + ((1540483477 * (h >>> 16) & 65535) << 16); | ||
h = 1540483477 * (65535 & (h ^= 255 & str.charCodeAt(i))) + (59797 * (h >>> 16) << 16); | ||
} | ||
return h = 1540483477 * (65535 & (h ^= h >>> 13)) + ((1540483477 * (h >>> 16) & 65535) << 16), | ||
((h ^= h >>> 15) >>> 0).toString(36); | ||
return (((h = 1540483477 * (65535 & (h ^= h >>> 13)) + (59797 * (h >>> 16) << 16)) ^ h >>> 15) >>> 0).toString(36); | ||
} | ||
@@ -24,2 +22,2 @@ | ||
value: !0 | ||
}), exports.default = murmurhash2_32_gc; | ||
}), exports.default = murmur2; |
/* eslint-disable */ | ||
// murmurhash2 via https://github.com/garycourt/murmurhash-js/blob/master/murmurhash2_gc.js | ||
function murmurhash2_32_gc(str) { | ||
var l = str.length, | ||
h = l ^ l, | ||
// Inspired by https://github.com/garycourt/murmurhash-js | ||
// Ported from https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash2.cpp#L37-L86 | ||
function murmur2(str) { | ||
// 'm' and 'r' are mixing constants generated offline. | ||
// They're not really 'magic', they just happen to work well. | ||
// const m = 0x5bd1e995; | ||
// const r = 24; | ||
// Initialize the hash | ||
var h = 0; // Mix 4 bytes at a time into the hash | ||
var k, | ||
i = 0, | ||
k; | ||
len = str.length; | ||
while (l >= 4) { | ||
for (; len >= 4; ++i, len -= 4) { | ||
k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24; | ||
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
k ^= k >>> 24; | ||
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16) ^ k; | ||
l -= 4; | ||
++i; | ||
} | ||
k = | ||
/* Math.imul(k, m): */ | ||
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16); | ||
k ^= | ||
/* k >>> r: */ | ||
k >>> 24; | ||
h = | ||
/* Math.imul(k, m): */ | ||
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16) ^ | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
} // Handle the last few bytes of the input array | ||
switch (l) { | ||
switch (len) { | ||
case 3: | ||
@@ -28,11 +41,16 @@ h ^= (str.charCodeAt(i + 2) & 0xff) << 16; | ||
h ^= str.charCodeAt(i) & 0xff; | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
} | ||
h = | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
} // Do a few final mixes of the hash to ensure the last few | ||
// bytes are well-incorporated. | ||
h ^= h >>> 13; | ||
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16); | ||
h ^= h >>> 15; | ||
return (h >>> 0).toString(36); | ||
h = | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16); | ||
return ((h ^ h >>> 15) >>> 0).toString(36); | ||
} | ||
export default murmurhash2_32_gc; | ||
export default murmur2; |
{ | ||
"name": "@emotion/hash", | ||
"version": "0.7.4", | ||
"version": "0.8.0", | ||
"description": "A MurmurHash2 implementation", | ||
@@ -5,0 +5,0 @@ "main": "dist/hash.cjs.js", |
// @flow | ||
/* eslint-disable */ | ||
// murmurhash2 via https://github.com/garycourt/murmurhash-js/blob/master/murmurhash2_gc.js | ||
// Inspired by https://github.com/garycourt/murmurhash-js | ||
// Ported from https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash2.cpp#L37-L86 | ||
export default function murmurhash2_32_gc(str: string) { | ||
var l = str.length, | ||
h = l ^ l, | ||
export default function murmur2(str: string) { | ||
// 'm' and 'r' are mixing constants generated offline. | ||
// They're not really 'magic', they just happen to work well. | ||
// const m = 0x5bd1e995; | ||
// const r = 24; | ||
// Initialize the hash | ||
var h = 0; | ||
// Mix 4 bytes at a time into the hash | ||
var k, | ||
i = 0, | ||
k | ||
while (l >= 4) { | ||
len = str.length; | ||
for (; len >= 4; ++i, len -= 4) { | ||
k = | ||
@@ -16,33 +27,39 @@ (str.charCodeAt(i) & 0xff) | | ||
((str.charCodeAt(++i) & 0xff) << 16) | | ||
((str.charCodeAt(++i) & 0xff) << 24) | ||
((str.charCodeAt(++i) & 0xff) << 24); | ||
k = (k & 0xffff) * 0x5bd1e995 + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16) | ||
k ^= k >>> 24 | ||
k = (k & 0xffff) * 0x5bd1e995 + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16) | ||
k = | ||
/* Math.imul(k, m): */ | ||
(k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0xe995) << 16); | ||
k ^= /* k >>> r: */ k >>> 24; | ||
h = | ||
((h & 0xffff) * 0x5bd1e995 + | ||
((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16)) ^ | ||
k | ||
l -= 4 | ||
++i | ||
/* Math.imul(k, m): */ | ||
((k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0xe995) << 16)) ^ | ||
/* Math.imul(h, m): */ | ||
((h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0xe995) << 16)); | ||
} | ||
switch (l) { | ||
// Handle the last few bytes of the input array | ||
switch (len) { | ||
case 3: | ||
h ^= (str.charCodeAt(i + 2) & 0xff) << 16 | ||
h ^= (str.charCodeAt(i + 2) & 0xff) << 16; | ||
case 2: | ||
h ^= (str.charCodeAt(i + 1) & 0xff) << 8 | ||
h ^= (str.charCodeAt(i + 1) & 0xff) << 8; | ||
case 1: | ||
h ^= str.charCodeAt(i) & 0xff | ||
h ^= str.charCodeAt(i) & 0xff; | ||
h = | ||
(h & 0xffff) * 0x5bd1e995 + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16) | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0xe995) << 16); | ||
} | ||
h ^= h >>> 13 | ||
h = (h & 0xffff) * 0x5bd1e995 + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16) | ||
h ^= h >>> 15 | ||
// Do a few final mixes of the hash to ensure the last few | ||
// bytes are well-incorporated. | ||
return (h >>> 0).toString(36) | ||
h ^= h >>> 13; | ||
h = | ||
/* Math.imul(h, m): */ | ||
(h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0xe995) << 16); | ||
return ((h ^ (h >>> 15)) >>> 0).toString(36); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14058
326
1