Bug 676700 - Slightly speed up js::IndexToId by converting directly to atom, not to string and then to atom. r=luke

This commit is contained in:
Jeff Walden
2011-08-04 19:21:25 -07:00
parent 89fa8b42bd
commit 494cd39d9c
3 changed files with 76 additions and 51 deletions

View File

@@ -42,6 +42,9 @@
*/
#include <stdlib.h>
#include <string.h>
#include "mozilla/RangedPtr.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"
@@ -665,6 +668,27 @@ js_InitAtomMap(JSContext *cx, JSAtomMap *map, AtomIndexMap *indices)
}
}
namespace js {
bool
IndexToIdSlow(JSContext *cx, uint32 index, jsid *idp)
{
JS_ASSERT(index > JSID_INT_MAX);
jschar buf[UINT32_CHAR_BUFFER_LENGTH];
RangedPtr<jschar> end(buf + JS_ARRAY_LENGTH(buf), buf, buf + JS_ARRAY_LENGTH(buf));
RangedPtr<jschar> start = BackfillIndexInCharBuffer(index, end);
JSAtom *atom = js_AtomizeChars(cx, start.get(), end - start);
if (!atom)
return false;
*idp = ATOM_TO_JSID(atom);
JS_ASSERT(js_CheckForStringIndex(*idp) == *idp);
return true;
}
} /* namespace js */
/* JSBOXEDWORD_INT_MAX as a string */
#define JSBOXEDWORD_INT_MAX_STRING "1073741823"