Subj : Re: can't understand difference in vars To : netscape.public.mozilla.jseng From : "Jashin Eugene" Date : Wed Mar 24 2004 02:25 pm Thanks a lot, to all! > JSBool MakeThree(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, > jsval *rval) > { > return JS_NewNumberValue(cx, 3, rval); > } > > As Marcello's followup points out, the internal representation of 3 > should be an int jsval, not a double jsval. Calling JS_NewDouble to > make a jsdouble allocated on the GC heap, just to contain a small > integer, is wasteful, besides not resulting in the desired operation. > > Always use JS_NewNumberValue, as it can optimize numbers into ints > instead of doubles where possible. > > /be .