-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve FakeMap implementation (#41)
- Loading branch information
1 parent
1fa5334
commit 323f3cf
Showing
5 changed files
with
25 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,31 @@ | ||
'use strict'; | ||
/* globals Symbol: true, Uint8Array: true, WeakMap: true */ | ||
/* globals Symbol: false, Uint8Array: false, WeakMap: false */ | ||
/*! | ||
* deep-eql | ||
* Copyright(c) 2013 Jake Luer <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
|
||
/*! | ||
* Module dependencies | ||
*/ | ||
|
||
var type = require('type-detect'); | ||
function FakeMap() { | ||
this.clear(); | ||
this._key = 'chai/deep-eql__' + Math.random() + Date.now(); | ||
} | ||
|
||
FakeMap.prototype = { | ||
clear: function clearMap() { | ||
this.keys = []; | ||
this.values = []; | ||
return this; | ||
}, | ||
set: function setMap(key, value) { | ||
var index = this.keys.indexOf(key); | ||
if (index >= 0) { | ||
this.values[index] = value; | ||
} else { | ||
this.keys.push(key); | ||
this.values.push(value); | ||
} | ||
return this; | ||
}, | ||
get: function getMap(key) { | ||
return this.values[this.keys.indexOf(key)]; | ||
return key[this._key]; | ||
}, | ||
delete: function deleteMap(key) { | ||
var index = this.keys.indexOf(key); | ||
if (index >= 0) { | ||
this.values = this.values.slice(0, index).concat(this.values.slice(index + 1)); | ||
this.keys = this.keys.slice(0, index).concat(this.keys.slice(index + 1)); | ||
set: function setMap(key, value) { | ||
if (!Object.isFrozen(key)) { | ||
Object.defineProperty(key, this._key, { | ||
value: value, | ||
configurable: true, | ||
}); | ||
} | ||
return this; | ||
}, | ||
}; | ||
|
||
var MemoizeMap = null; | ||
if (typeof WeakMap === 'function') { | ||
MemoizeMap = WeakMap; | ||
} else { | ||
MemoizeMap = FakeMap; | ||
} | ||
|
||
var MemoizeMap = typeof WeakMap === 'function' ? WeakMap : FakeMap; | ||
/*! | ||
* Check to see if the MemoizeMap has recorded a result of the two operands | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters