From 0469abd4a9c9270a1fdc962969e36e63699af8b4 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 10 Dec 2017 21:51:33 +0100 Subject: upgrade dependencies --- node_modules/source-map/lib/array-set.js | 37 +++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'node_modules/source-map/lib/array-set.js') 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.'); }; -- cgit v1.2.3