-
-
Notifications
You must be signed in to change notification settings - Fork 688
feat: Map support constructor initialization with MapInitialEntries #2941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
970fdb2
6ac8e6a
d746161
71fefe7
4b5981f
bcd86f2
5d0ecdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -73,14 +73,12 @@ export class Map<K,V> { | |||||
| private entriesOffset: i32 = 0; | ||||||
| private entriesCount: i32 = 0; | ||||||
|
|
||||||
| constructor(initialEntries: MapInitialEntries<K,V> = []) { | ||||||
| let entriesLength = initialEntries.length; | ||||||
|
|
||||||
| if (entriesLength > 0) { | ||||||
| if (entriesLength >= this.entriesCapacity) this.bucketsMask = entriesLength; | ||||||
| constructor(initialEntries: MapInitialEntries<K,V> | null = null) { | ||||||
| if (initialEntries) { | ||||||
|
Member
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. Just use early return:
Suggested change
This will reduce one level of ident
Member
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. My bad for suggesting that |
||||||
| if (initialEntries.length >= this.entriesCapacity) this.bucketsMask = initialEntries.length; | ||||||
| this.rehash((this.bucketsMask << 1) | 1); | ||||||
|
|
||||||
| for (let i = 0; i < entriesLength; i++) { | ||||||
| for (let i = 0; i < initialEntries.length; i++) { | ||||||
|
Member
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. plz cache |
||||||
| let key = initialEntries[i].key; | ||||||
| let value = initialEntries[i].value; | ||||||
| let hashCode = HASH<K>(key); | ||||||
|
|
||||||
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.
plz revert this cached entriesLength var and use instead
initialEntries.length