Bug 1028866 part 2 - Cleanup NewStringCopyZ. r=luke

--HG--
extra : rebase_source : 321aae85dd6a3e2fa90474ceed9bd03347f528a8
This commit is contained in:
Jan de Mooij 2014-06-24 17:33:29 +02:00
parent f6453dde7c
commit 6f1fd23160
2 changed files with 2 additions and 25 deletions

View File

@ -5234,22 +5234,11 @@ JS_NewStringCopyN(JSContext *cx, const char *s, size_t n)
JS_PUBLIC_API(JSString *)
JS_NewStringCopyZ(JSContext *cx, const char *s)
{
size_t n;
jschar *js;
JSString *str;
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
if (!s || !*s)
return cx->runtime()->emptyString;
n = strlen(s);
js = InflateString(cx, s, &n);
if (!js)
return nullptr;
str = NewString<CanGC>(cx, js, n);
if (!str)
js_free(js);
return str;
return NewStringCopyZ<CanGC>(cx, s);
}
JS_PUBLIC_API(bool)

View File

@ -4418,19 +4418,7 @@ template <AllowGC allowGC>
JSFlatString *
js::NewStringCopyZ(ExclusiveContext *cx, const jschar *s)
{
size_t n = js_strlen(s);
if (JSFatInlineString::twoByteLengthFits(n))
return NewFatInlineString<allowGC>(cx, Range<const jschar>(s, n));
size_t m = (n + 1) * sizeof(jschar);
jschar *news = (jschar *) cx->malloc_(m);
if (!news)
return nullptr;
js_memcpy(news, s, m);
JSFlatString *str = NewString<allowGC>(cx, news, n);
if (!str)
js_free(news);
return str;
return NewStringCopyN<allowGC>(cx, s, js_strlen(s));
}
template JSFlatString *