Closed
Bug 530240
Opened 15 years ago
Closed 15 years ago
[FIX]Make jsstr's NormalizeThis somewhat faster for String objects
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: bzbarsky, Assigned: bzbarsky)
Details
(Whiteboard: fixed-in-tracemonkey)
Attachments
(1 file, 2 obsolete files)
2.42 KB,
patch
|
brendan
:
review+
|
Details | Diff | Splinter Review |
I think next to JSString being the this, this is the common case; it's not much code, and speeds up some dromaeo string tests up to 10%.
Assignee | ||
Comment 1•15 years ago
|
||
One question I had was whether I want OBJ_GET_CLASS or STOBJ_GET_CLASS and whether I need a request check somewhere in here...
Attachment #413762 -
Flags: review?(brendan)
Comment 2•15 years ago
|
||
Comment on attachment 413762 [details] [diff] [review] Proposed fix I don't think you need a request check, since this method is only called from a purely internal macro. >diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp >+ // js_GetPrimitiveThis seems to to a bunch of work (like calls to s/to to/to do/ >+ // JS_THIS_OBJECT) which we don't need in the common case (where >+ // vp[1] is a String object) here. /* * */ -style comments >+ if (!JSVAL_IS_PRIMITIVE(vp[1]) && >+ OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(vp[1])) == &js_StringClass) { None of the above, it's obj->getClass() now (the others just haven't been terminated with extreme prejudice yet). r=me if you want it; I have difficulty thinking there's anything else here Brendan might see that I missed.
Attachment #413762 -
Flags: review+
Assignee | ||
Comment 3•15 years ago
|
||
Would still like a once-over, specifically on the assumption that vp[1] is JSVAL_IS_OBJECT here (because the macro checked for JSVAL_IS_STRING, we already checked for JSVAL_IS_NULL, and I can't see how to get the other primitives in here without them being boxed) that I'm making. If that assumption is bogus, I'd love to know (and know why).
Attachment #413762 -
Attachment is obsolete: true
Attachment #413770 -
Flags: review?(brendan)
Attachment #413762 -
Flags: review?(brendan)
Assignee | ||
Comment 4•15 years ago
|
||
Attachment #413771 -
Flags: review?(brendan)
Updated•15 years ago
|
Attachment #413770 -
Attachment is obsolete: true
Attachment #413770 -
Flags: review?(brendan)
Comment 5•15 years ago
|
||
Comment on attachment 413771 [details] [diff] [review] Er, with working assert >@@ -644,19 +644,29 @@ JSClass js_StringClass = { > > static JSString * > NormalizeThis(JSContext *cx, jsval *vp) > { > JSString *str; > > if (JSVAL_IS_NULL(vp[1]) && JSVAL_IS_NULL(JS_THIS(cx, vp))) > return NULL; Nit: blank line here. >+ /* >+ * js_GetPrimitiveThis seems to do a bunch of work (like calls to >+ * JS_THIS_OBJECT) which we don't need in the common case (where >+ * vp[1] is a String object) here. >+ */ >+ JS_ASSERT(!JSVAL_IS_PRIMITIVE(vp[1])); >+ if (JSVAL_TO_OBJECT(vp[1])->getClass() == &js_StringClass) { >+ str = JSVAL_TO_STRING(JSVAL_TO_OBJECT(vp[1])->fslots[JSSLOT_PRIMITIVE_THIS]); This is fine and generates optimal code, but for debugging and conciseness, consider JSObject *obj = JSVAL_TO_OBJECT(vp[1]) and use obj instead of the lengthy JSVAL_TO_OBJECT(vp[1]). /be
Attachment #413771 -
Flags: review?(brendan) → review+
Updated•15 years ago
|
Summary: [FIX]Make jsstr's NomalizeThis somewhat faster for String objects → [FIX]Make jsstr's NormalizeThis somewhat faster for String objects
Assignee | ||
Comment 6•15 years ago
|
||
> Nit: blank line here.
> consider JSObject *obj = JSVAL_TO_OBJECT(vp[1])
Both done.
Assignee | ||
Comment 7•15 years ago
|
||
Pushed http://hg.mozilla.org/mozilla-central/rev/e254e5dcd2a1
Whiteboard: fixed-in-tracemonkey
Assignee | ||
Comment 8•15 years ago
|
||
Er... I meant http://hg.mozilla.org/tracemonkey/rev/e254e5dcd2a1
Assignee | ||
Comment 9•15 years ago
|
||
> specifically on the assumption that vp[1] is JSVAL_IS_OBJECT here jsreftest says this assumption is false. Testcase: eval("x=false; x.__proto__.charAt = String.prototype.charAt; x.charAt(0)") ); gives me JSVAL_FALSE as vp[1]. Pushed http://hg.mozilla.org/tracemonkey/rev/efb6d958c53f to handle that.
Comment 10•15 years ago
|
||
Sorry, I should have remembered JSFUN_THISP_PRIMITIVE better. /be
Comment 11•15 years ago
|
||
You weren't the only one. In any case: huzzah for tests!
Comment 12•15 years ago
|
||
http://hg.mozilla.org/mozilla-central/rev/e254e5dcd2a1
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•