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);
}
}
-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?
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,
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));
}
#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);
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];
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));
}
RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDefaultICULocale) {
- SealHandleScope shs(isolate);
+ HandleScope scope(isolate);
+ Factory* factory = isolate->factory();
ASSERT(args.length() == 0);
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"));
}
// 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);
}