зеркало из https://github.com/mozilla/pjs.git
Actually populate the dtoa cache correctly in js::IndexToString. r=luke over irl
--HG-- extra : rebase_source : eef9c49c3a8cc41d6c0926734e35743e25f4ff23
This commit is contained in:
Родитель
301e16145c
Коммит
1e07dbc39c
|
@ -4,13 +4,15 @@
|
|||
|
||||
#include "tests.h"
|
||||
|
||||
#include "jscntxt.h"
|
||||
#include "jscompartment.h"
|
||||
#include "jsnum.h"
|
||||
|
||||
#include "vm/String.h"
|
||||
#include "vm/String-inl.h"
|
||||
|
||||
BEGIN_TEST(testIndexToString)
|
||||
{
|
||||
struct TestPair {
|
||||
const struct TestPair {
|
||||
uint32 num;
|
||||
const char *expected;
|
||||
} tests[] = {
|
||||
|
@ -43,9 +45,13 @@ BEGIN_TEST(testIndexToString)
|
|||
};
|
||||
|
||||
for (size_t i = 0, sz = JS_ARRAY_LENGTH(tests); i < sz; i++) {
|
||||
JSString *str = js::IndexToString(cx, tests[i].num);
|
||||
uint32 u = tests[i].num;
|
||||
JSString *str = js::IndexToString(cx, u);
|
||||
CHECK(str);
|
||||
|
||||
if (!JSAtom::hasUintStatic(u))
|
||||
CHECK(cx->compartment->dtoaCache.lookup(10, u) == str);
|
||||
|
||||
JSBool match = JS_FALSE;
|
||||
CHECK(JS_StringEqualsAscii(cx, str, tests[i].expected, &match));
|
||||
CHECK(match);
|
||||
|
|
|
@ -1269,13 +1269,13 @@ NumberToString(JSContext *cx, jsdouble d)
|
|||
}
|
||||
|
||||
JSFixedString *
|
||||
IndexToString(JSContext *cx, uint32 u)
|
||||
IndexToString(JSContext *cx, uint32 index)
|
||||
{
|
||||
if (JSAtom::hasUintStatic(u))
|
||||
return &JSAtom::uintStatic(u);
|
||||
if (JSAtom::hasUintStatic(index))
|
||||
return &JSAtom::uintStatic(index);
|
||||
|
||||
JSCompartment *c = cx->compartment;
|
||||
if (JSFixedString *str = c->dtoaCache.lookup(10, u))
|
||||
if (JSFixedString *str = c->dtoaCache.lookup(10, index))
|
||||
return str;
|
||||
|
||||
JSShortString *str = js_NewGCShortString(cx);
|
||||
|
@ -1291,15 +1291,16 @@ IndexToString(JSContext *cx, uint32 u)
|
|||
RangedPtr<jschar> cp = end;
|
||||
*cp = '\0';
|
||||
|
||||
uint32 u = index;
|
||||
do {
|
||||
jsuint newu = u / 10, digit = u % 10;
|
||||
uint32 newu = u / 10, digit = u % 10;
|
||||
*--cp = '0' + digit;
|
||||
u = newu;
|
||||
} while (u > 0);
|
||||
|
||||
str->initAtOffsetInBuffer(cp.get(), end - cp);
|
||||
|
||||
c->dtoaCache.cache(10, u, str);
|
||||
c->dtoaCache.cache(10, index, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче