Closed
Bug 934718
Opened 11 years ago
Closed 11 years ago
Simplify some HashTable internal maths, kill some JS_STATIC_ASSERT usage
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla28
People
(Reporter: Waldo, Assigned: Waldo)
References
Details
(Whiteboard: [qa-])
Attachments
(1 file)
5.48 KB,
patch
|
luke
:
review+
|
Details | Diff | Splinter Review |
Some of the current static-asserts of hash table constants are 1) not ever tested, because staticAsserts is never called (and therefore never instantiated), and 2) crazy, because the constants involved are scaled in offsetting ways by 2**7, 2**8, 2, and similar, but not at all in obviously corresponding ways. Rewrite the math to be significantly clearer about what it does, by splitting alpha fractions into numerator-denominator constant pairs, and replace the relevant JS_STATIC_ASSERT with C++11 static_asserts to the same effect (if not in the same ways).
Attachment #827060 -
Flags: review?(luke)
Comment 1•11 years ago
|
||
Bug 929620 comment 1 might be worth considering as part of this bug.
Comment 3•11 years ago
|
||
Comment on attachment 827060 [details] [diff] [review]
Patch
Review of attachment 827060 [details] [diff] [review]:
-----------------------------------------------------------------
Nice.
::: js/public/HashTable.h
@@ +926,5 @@
> + // Hash-table alpha is conceptually a fraction, but to avoid floating-point
> + // math we implement it as a ratio of integers.
> + static const uint8_t sAlphaDenominator = 4;
> + static const uint8_t sMinAlphaNumerator = 1; // min alpha: 1/4
> + static const uint8_t sMaxAlphaNumerator = 3; // max alpha: 3/4
Whoa, I can like, totally wrap my ahead around this the first time.
@@ +994,5 @@
> + "numerator calculation below could potentially overflow");
> +
> + // Compute the smallest capacity allowing |length| elements to be
> + // inserted without rehashing: ceil(length / max-alpha). (Ceiling
> + // integral division: <http://stackoverflow.com/a/2745086/115698>.)
Is stack overflow the best URL we can embed here? Also, to make it more readable, perhaps you'd consider factoring this out into some JS_ALWAYS_INLINE function (either in HashTable or a mfbt math helper .h).
Attachment #827060 -
Flags: review?(luke) → review+
Assignee | ||
Comment 4•11 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/bbbeb0e593ec
I assume you mean like the Stanford bits algorithms page, or something -- no, I didn't find anything elsewhere for ceiling division.
As for abstracting it, might be nice, but I don't think *this* case is going to look any nicer, given that max-alpha is a fraction, requiring its being split into two parts to gunk up *both* halves of the division. Next time there's a use for ceiling division, with non-fugly operands, it seems like a good idea to add the helper.
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla28
Updated•11 years ago
|
Whiteboard: [qa-]
You need to log in
before you can comment on or make changes to this bug.
Description
•