Commit fe3e5706 authored by ishell@chromium.org's avatar ishell@chromium.org

Callers of Heap::AllocateStringFromOneByte() and Heap::AllocateStringFromUtf8() handlified.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/239083005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20821 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 28285083
......@@ -281,9 +281,21 @@ Handle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
Handle<String> Factory::NewStringFromUtf8(Vector<const char> string,
PretenureFlag pretenure) {
// Check for ASCII first since this is the common case.
const char* start = string.start();
int length = string.length();
int non_ascii_start = String::NonAsciiStart(start, length);
if (non_ascii_start >= length) {
// If the string is ASCII, we do not need to convert the characters
// since UTF8 is backwards compatible with ASCII.
return NewStringFromOneByte(Vector<const uint8_t>::cast(string), pretenure);
}
// Non-ASCII and we need to decode.
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateStringFromUtf8(string, pretenure),
isolate()->heap()->AllocateStringFromUtf8Slow(string,
non_ascii_start,
pretenure),
String);
}
......
......@@ -85,22 +85,6 @@ void PromotionQueue::ActivateGuardIfOnTheSamePage() {
}
MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> str,
PretenureFlag pretenure) {
// Check for ASCII first since this is the common case.
const char* start = str.start();
int length = str.length();
int non_ascii_start = String::NonAsciiStart(start, length);
if (non_ascii_start >= length) {
// If the string is ASCII, we do not need to convert the characters
// since UTF8 is backwards compatible with ASCII.
return AllocateStringFromOneByte(str, pretenure);
}
// Non-ASCII and we need to decode.
return AllocateStringFromUtf8Slow(str, non_ascii_start, pretenure);
}
template<>
bool inline Heap::IsOneByte(Vector<const char> str, int chars) {
// TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported?
......
......@@ -788,16 +788,6 @@ class Heap {
MUST_USE_RESULT MaybeObject* AllocateStringFromOneByte(
Vector<const uint8_t> str,
PretenureFlag pretenure = NOT_TENURED);
// TODO(dcarney): remove this function.
MUST_USE_RESULT inline MaybeObject* AllocateStringFromOneByte(
Vector<const char> str,
PretenureFlag pretenure = NOT_TENURED) {
return AllocateStringFromOneByte(Vector<const uint8_t>::cast(str),
pretenure);
}
MUST_USE_RESULT inline MaybeObject* AllocateStringFromUtf8(
Vector<const char> str,
PretenureFlag pretenure = NOT_TENURED);
MUST_USE_RESULT MaybeObject* AllocateStringFromUtf8Slow(
Vector<const char> str,
int non_ascii_start,
......
......@@ -9600,13 +9600,13 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DateParseString) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_DateLocalTimezone) {
SealHandleScope shs(isolate);
HandleScope scope(isolate);
ASSERT(args.length() == 1);
CONVERT_DOUBLE_ARG_CHECKED(x, 0);
const char* zone =
isolate->date_cache()->LocalTimezone(static_cast<int64_t>(x));
return isolate->heap()->AllocateStringFromUtf8(CStrVector(zone));
return *isolate->factory()->NewStringFromUtf8(CStrVector(zone));
}
......@@ -13610,6 +13610,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetHeapUsage) {
#ifdef V8_I18N_SUPPORT
RUNTIME_FUNCTION(MaybeObject*, Runtime_CanonicalizeLanguageTag) {
HandleScope scope(isolate);
Factory* factory = isolate->factory();
ASSERT(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(String, locale_id_str, 0);
......@@ -13626,7 +13627,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CanonicalizeLanguageTag) {
uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY,
&icu_length, &error);
if (U_FAILURE(error) || icu_length == 0) {
return isolate->heap()->AllocateStringFromOneByte(CStrVector(kInvalidTag));
return *factory->NewStringFromOneByte(OneByteVector(kInvalidTag));
}
char result[ULOC_FULLNAME_CAPACITY];
......@@ -13635,10 +13636,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CanonicalizeLanguageTag) {
uloc_toLanguageTag(icu_result, result, ULOC_FULLNAME_CAPACITY, TRUE, &error);
if (U_FAILURE(error)) {
return isolate->heap()->AllocateStringFromOneByte(CStrVector(kInvalidTag));
return *factory->NewStringFromOneByte(OneByteVector(kInvalidTag));
}
return isolate->heap()->AllocateStringFromOneByte(CStrVector(result));
return *factory->NewStringFromOneByte(OneByteVector(result));
}
......@@ -13690,7 +13691,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_AvailableLocalesOf) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDefaultICULocale) {
SealHandleScope shs(isolate);
HandleScope scope(isolate);
Factory* factory = isolate->factory();
ASSERT(args.length() == 0);
......@@ -13702,10 +13704,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDefaultICULocale) {
uloc_toLanguageTag(
default_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status);
if (U_SUCCESS(status)) {
return isolate->heap()->AllocateStringFromOneByte(CStrVector(result));
return *factory->NewStringFromOneByte(OneByteVector(result));
}
return isolate->heap()->AllocateStringFromOneByte(CStrVector("und"));
return *factory->NewStringFromOneByte(STATIC_ASCII_VECTOR("und"));
}
......@@ -14416,13 +14418,13 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetAndClearOverflowedStackTrace) {
// Returns V8 version as a string.
RUNTIME_FUNCTION(MaybeObject*, Runtime_GetV8Version) {
SealHandleScope shs(isolate);
HandleScope scope(isolate);
ASSERT_EQ(args.length(), 0);
const char* version_string = v8::V8::GetVersion();
return isolate->heap()->AllocateStringFromOneByte(CStrVector(version_string),
NOT_TENURED);
return *isolate->factory()->NewStringFromOneByte(
OneByteVector(version_string), NOT_TENURED);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment