Closed
Bug 562809
Opened 14 years ago
Closed 14 years ago
js::HashTable::init(n) should guarantee success of next 'n' add()s
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
People
(Reporter: dwitte, Assigned: dwitte)
References
Details
(Whiteboard: fixed-in-tracemonkey)
Attachments
(1 file)
3.31 KB,
patch
|
luke
:
review+
|
Details | Diff | Splinter Review |
http://mxr.mozilla.org/mozilla-central/source/js/src/jshashtable.h#290 Currently it rounds 'n' up to the nearest power of 2, and sizes the hash thusly. But when add()ing an element, alpha gets involved, which may result in an appropriately-presized hash being expanded. It would be nice if init() took alpha into account, such that those 'n' add()s could be guaranteed.
Comment 1•14 years ago
|
||
I was wrong on IRC, this is the same as JS_DHashTableInit. The parameter name is capacity, so rounding up to power of two is the right thing given the meaning of the parameter. Callers use JS_DHASH_DEFAULT_CAPACITY(n) where n is the number of initial entries. Looking back, this seems silly to foist off on all callers. I may have been thinking that Init would be called with a guess at capacity rather than an exact (or simpler better guess at) number of initial or near-term entries. Anyway, if jshashtable.h takes the more usable route, please document the difference. We should try to retire jsdhash/pldhash at some point, in favor of jshashtable. I remember Luke worrying about template bloat, but let's find out how bad of a problem that is. /be
Assignee | ||
Comment 2•14 years ago
|
||
Uses a statically defined sInvMaxAlpha. I went with a << 7 shift, rather than 8, to keep it fitting in a uint8. (Which is useful so that the max table size of 2^24 is still achievable.)
Comment 3•14 years ago
|
||
Comment on attachment 443691 [details] [diff] [review] patch Looks good, thanks! >+ /* Correct for sMaxAlphaFrac such that the table will not resize >+ when adding 'length' entries. */ Nit: SM does: /* * comments */
Attachment #443691 -
Flags: review?(lw) → review+
Assignee | ||
Comment 4•14 years ago
|
||
Comment on attachment 443691 [details] [diff] [review] patch http://hg.mozilla.org/tracemonkey/rev/2cc1ad9809b2
Assignee | ||
Updated•14 years ago
|
Whiteboard: fixed-in-tracemonkey
Comment 5•14 years ago
|
||
http://hg.mozilla.org/mozilla-central/rev/2cc1ad9809b2
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•