hostlist: improve hash perf.
This commit is contained in:
parent
4740a2fff3
commit
9cd70fb589
@ -271,17 +271,12 @@ HostList.prototype.getHost = function getHost() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HostList.prototype.freshBucket = function freshBucket(entry) {
|
HostList.prototype.freshBucket = function freshBucket(entry) {
|
||||||
var size = 0;
|
var addr = entry.addr;
|
||||||
var bw, hash, index;
|
var src = entry.src;
|
||||||
|
var data, hash, index;
|
||||||
|
|
||||||
size += entry.addr.host.length;
|
data = util.concat(addr.raw, src.raw);
|
||||||
size += entry.src.host.length;
|
hash = murmur3(data, 0xfba4c795);
|
||||||
|
|
||||||
bw = new StaticWriter(size);
|
|
||||||
bw.writeString(entry.addr.host, 'ascii');
|
|
||||||
bw.writeString(entry.src.host, 'ascii');
|
|
||||||
|
|
||||||
hash = murmur3(bw.render(), 0xfba4c795);
|
|
||||||
index = hash % this.fresh.length;
|
index = hash % this.fresh.length;
|
||||||
|
|
||||||
return this.fresh[index];
|
return this.fresh[index];
|
||||||
@ -295,8 +290,8 @@ HostList.prototype.freshBucket = function freshBucket(entry) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HostList.prototype.usedBucket = function usedBucket(entry) {
|
HostList.prototype.usedBucket = function usedBucket(entry) {
|
||||||
var data = new Buffer(entry.addr.host, 'ascii');
|
var addr = entry.addr;
|
||||||
var hash = murmur3(data, 0xfba4c795);
|
var hash = murmur3(addr.raw, 0xfba4c795);
|
||||||
var index = hash % this.used.length;
|
var index = hash % this.used.length;
|
||||||
return this.used[index];
|
return this.used[index];
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user