Closed Bug 651940 Opened 13 years ago Closed 13 years ago

When hashing a jsid, assert that js_CheckForStringIndex(id) == id

Categories

(Core :: JavaScript Engine, defect)

Other Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla8

People

(Reporter: jorendorff, Assigned: jorendorff)

Details

Attachments

(1 file, 1 obsolete file)

It is always a mistake to hash a jsid of the string "0" or "-1".

Asserting to that effect and running the test suite reveals just one bug.

I need to make HASH0 public for bug 637985 so I'm going to do it here while I'm touching the definition.
Attached patch v1 (obsolete) — Splinter Review
Assignee: general → jorendorff
Attachment #527613 - Flags: review?(jwalden+bmo)
Comment on attachment 527613 [details] [diff] [review]
v1

>diff --git a/js/src/jsatom.h b/js/src/jsatom.h

>+extern jsid
>+js_CheckForStringIndex(jsid id);

I assume this method wasn't actually being inlined before, but I'd be interested to know whether that was really the case in general or not, if you investigated.  No need to do so if you didn't, just curiosity.


>+static JS_ALWAYS_INLINE JSHashNumber
>+HashId(jsid id)
>+{
>+    JS_ASSERT(js_CheckForStringIndex(id) == id);
>+    return JS_GOLDEN_RATIO *
>+#if JS_BYTES_PER_WORD == 4
>+        JSHashNumber(JSID_BITS(id));
>+#elif JS_BYTES_PER_WORD == 8
>+        JSHashNumber(JSID_BITS(id)) ^ JSHashNumber(JSID_BITS(id) >> 32);
>+#else
>+# error "Unsupported configuration"
>+#endif
>+}

(m * a ^ b) === ((m * a) ^ b), but it was m * (a ^ b) before.  Also, I'd rather not see an #if nested within an expression like this, because then it's harder to see which part of the #if actually ended up being used.  I suggest this instead, to address both concerns in one swell foop:

>     JSHashNumber n =
> #if JS_BYTES_PER_WORD == 4
>         JSHashNumber(JSID_BITS(id));
> #elif JS_BYTES_PER_WORD == 8
>         JSHashNumber(JSID_BITS(id)) ^ JSHashNumber(JSID_BITS(id) >> 32);
> #else
> # error "Unsupported configuration"
> #endif
> return n * JS_GOLDEN_RATIO;
Attachment #527613 - Flags: review?(jwalden+bmo) → review-
Attached patch v2Splinter Review
Good save. Here's the updated patch.
Attachment #527613 - Attachment is obsolete: true
Attachment #542254 - Flags: review?(jwalden+bmo)
Attachment #542254 - Flags: review?(jwalden+bmo) → review+
http://hg.mozilla.org/mozilla-central/rev/cad13a541e30
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Whiteboard: [inbound]
Target Milestone: --- → mozilla8
No longer depends on: 675581
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: