This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Replace arrays and HashMap
with native Map
(with a fallback shim implementation)
#15114
Closed
Closed
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c187d7
perf(copy): use ES6 Map to track source/destination objects
jbedard 8f4eab4
fixup! perf(copy): Saving the last key/index lookup in ESMapShim
jbedard 95f9179
fixup! perf(copy): replace Map feature-test with native-test
jbedard 4db3ac1
refactor(copy): avoid creating source/dest Map for simple copies
jbedard fdba297
refactor(HashMap): use `ES6Map` under the hood
gkalpak a83f60e
refactor(*): replace `HashMap` with `NgMap` (former `ES6Map`)
gkalpak dcbb707
test(hashKey): add tests for `hashKey()`
gkalpak 604d876
fixup! refactor(*): replace `HashMap` with `NgMap` (former `ES6Map`)
gkalpak a7f8d63
fixup! refactor(*): replace `HashMap` with `NgMap` (former `ES6Map`)
gkalpak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -89,6 +89,7 @@ | |
hasOwnProperty, | ||
createMap, | ||
stringify, | ||
ES6Map, | ||
|
||
NODE_TYPE_ELEMENT, | ||
NODE_TYPE_ATTRIBUTE, | ||
|
@@ -752,6 +753,7 @@ function arrayRemove(array, value) { | |
// A minimal ES6 Map implementation. | ||
// Should be bug/feature equivelent to the native implementations of supported browsers. | ||
// See https://kangax.github.io/compat-table/es6/#test-Map | ||
var nanPlaceholder = Object.create(null); | ||
function ES6MapShim() { | ||
this._keys = []; | ||
this._values = []; | ||
|
@@ -765,23 +767,37 @@ ES6MapShim.prototype = { | |
} | ||
return (this._lastIndex = (this._keys.indexOf(this._lastKey = key))); | ||
}, | ||
_transformKey: function(key) { | ||
return isNumberNaN(key) ? nanPlaceholder : key; | ||
}, | ||
get: function(key) { | ||
var idx = this._idx(key); | ||
var idx = this._idx(this._transformKey(key)); | ||
if (idx !== -1) { | ||
return this._values[idx]; | ||
} | ||
}, | ||
set: function(key, value) { | ||
key = this._transformKey(key); | ||
var idx = this._idx(key); | ||
if (idx === -1) { | ||
idx = this._lastIndex = this._keys.length; | ||
this._lastKey = key; | ||
} | ||
this._keys[idx] = key; | ||
this._values[idx] = value; | ||
|
||
// Support: IE11 | ||
// Do not `return this` to simulate the partial IE11 implementation | ||
}, | ||
delete: function(key) { | ||
var idx = this._idx(this._transformKey(key)); | ||
if (idx === -1) { | ||
return false; | ||
} | ||
this._keys.splice(idx, 1); | ||
this._values.splice(idx, 1); | ||
this._lastKey = NaN; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only have to reset the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not true. Actually true, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right... |
||
this._lastIndex = -1; | ||
return true; | ||
} | ||
}; | ||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't deleting this line break something? Every assignment of
lastIndex
must be beside an assignment tolastKey
(and the reverse)...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this._lastKey
has been set tokey
in the previous call to_idx()
.We need to re-assign
this._lastIndex
here, because the currently set-1
won't be true any more (since we are adding the item), butthis._lastKey
stays the same.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, looks like you're right. That isn't really obvious just looking at this though. Worth putting it back? Or more likely just a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might not be obvious if you are trying to figure out why it is being deleted, but if you look at the code (without knowing it was ever there), I think it is clearer without the comment.
I am fine adding if you still think it helps, though.