diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
commit | 0469abd4a9c9270a1fdc962969e36e63699af8b4 (patch) | |
tree | f9864d4a4148621378958794cbbfdc2393733283 /node_modules/source-map/lib/array-set.js | |
parent | 6947e79bbc258f7bc96af424ddb71a511f0c15a3 (diff) |
upgrade dependencies
Diffstat (limited to 'node_modules/source-map/lib/array-set.js')
-rw-r--r-- | node_modules/source-map/lib/array-set.js | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/node_modules/source-map/lib/array-set.js b/node_modules/source-map/lib/array-set.js index 51dffeb59..fbd5c81ca 100644 --- a/node_modules/source-map/lib/array-set.js +++ b/node_modules/source-map/lib/array-set.js @@ -7,6 +7,7 @@ var util = require('./util'); var has = Object.prototype.hasOwnProperty; +var hasNativeMap = typeof Map !== "undefined"; /** * A data structure which is a combination of an array and a set. Adding a new @@ -16,7 +17,7 @@ var has = Object.prototype.hasOwnProperty; */ function ArraySet() { this._array = []; - this._set = Object.create(null); + this._set = hasNativeMap ? new Map() : Object.create(null); } /** @@ -37,7 +38,7 @@ ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { * @returns Number */ ArraySet.prototype.size = function ArraySet_size() { - return Object.getOwnPropertyNames(this._set).length; + return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length; }; /** @@ -46,14 +47,18 @@ ArraySet.prototype.size = function ArraySet_size() { * @param String aStr */ ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { - var sStr = util.toSetString(aStr); - var isDuplicate = has.call(this._set, sStr); + var sStr = hasNativeMap ? aStr : util.toSetString(aStr); + var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr); var idx = this._array.length; if (!isDuplicate || aAllowDuplicates) { this._array.push(aStr); } if (!isDuplicate) { - this._set[sStr] = idx; + if (hasNativeMap) { + this._set.set(aStr, idx); + } else { + this._set[sStr] = idx; + } } }; @@ -63,8 +68,12 @@ ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { * @param String aStr */ ArraySet.prototype.has = function ArraySet_has(aStr) { - var sStr = util.toSetString(aStr); - return has.call(this._set, sStr); + if (hasNativeMap) { + return this._set.has(aStr); + } else { + var sStr = util.toSetString(aStr); + return has.call(this._set, sStr); + } }; /** @@ -73,10 +82,18 @@ ArraySet.prototype.has = function ArraySet_has(aStr) { * @param String aStr */ ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { - var sStr = util.toSetString(aStr); - if (has.call(this._set, sStr)) { - return this._set[sStr]; + if (hasNativeMap) { + var idx = this._set.get(aStr); + if (idx >= 0) { + return idx; + } + } else { + var sStr = util.toSetString(aStr); + if (has.call(this._set, sStr)) { + return this._set[sStr]; + } } + throw new Error('"' + aStr + '" is not in the set.'); }; |