Commit 4fcc0668 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Handlify LookupSingleCharacterStringFromCode.

R=ishell@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20559 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3d0c96f8
......@@ -287,6 +287,14 @@ MaybeHandle<SeqTwoByteString> Factory::NewRawTwoByteString(
}
Handle<String> Factory::LookupSingleCharacterStringFromCode(uint32_t index) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->LookupSingleCharacterStringFromCode(index),
String);
}
// Returns true for a character in a range. Both limits are inclusive.
static inline bool Between(uint32_t character, uint32_t from, uint32_t to) {
// This makes uses of the the unsigned wraparound.
......@@ -469,7 +477,7 @@ Handle<String> Factory::NewProperSubString(Handle<String> str,
int length = end - begin;
if (length <= 0) return empty_string();
if (length == 1) {
return LookupSingleCharacterStringFromCode(isolate(), str->Get(begin));
return LookupSingleCharacterStringFromCode(str->Get(begin));
}
if (length == 2) {
// Optimization for 2-byte strings often used as keys in a decompression
......
......@@ -142,6 +142,8 @@ class Factory V8_FINAL {
int length,
PretenureFlag pretenure = NOT_TENURED);
Handle<String> LookupSingleCharacterStringFromCode(uint32_t index);
// Create a new cons string object which consists of a pair of strings.
MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left,
Handle<String> right);
......
......@@ -179,15 +179,6 @@ Handle<Object> GetProperty(Handle<JSReceiver> obj,
}
Handle<String> LookupSingleCharacterStringFromCode(Isolate* isolate,
uint32_t index) {
CALL_HEAP_FUNCTION(
isolate,
isolate->heap()->LookupSingleCharacterStringFromCode(index),
String);
}
// Wrappers for scripts are kept alive and cached in weak global
// handles referred from foreign objects held by the scripts as long as
// they are used. When they are not used anymore, the garbage
......
......@@ -302,9 +302,6 @@ Handle<Object> HasProperty(Handle<JSReceiver> obj, Handle<Object> key);
Handle<Object> GetProperty(Handle<JSReceiver> obj, const char* name);
Handle<String> LookupSingleCharacterStringFromCode(Isolate* isolate,
uint32_t index);
// Get the JS object corresponding to the given script; create it
// if none exists.
Handle<JSValue> GetScriptWrapper(Handle<Script> script);
......
......@@ -4097,7 +4097,7 @@ HInstruction* HStringCharFromCode::New(
if (std::isfinite(c_code->DoubleValue())) {
uint32_t code = c_code->NumberValueAsInteger32() & 0xffff;
return HConstant::New(zone, context,
LookupSingleCharacterStringFromCode(isolate, code));
isolate->factory()->LookupSingleCharacterStringFromCode(code));
}
return HConstant::New(zone, context, isolate->factory()->empty_string());
}
......
......@@ -257,8 +257,7 @@ MaybeHandle<Object> JsonParser<seq_ascii>::ParseJson() {
break;
default:
message = "unexpected_token";
Handle<Object> name =
LookupSingleCharacterStringFromCode(isolate_, c0_);
Handle<Object> name = factory->LookupSingleCharacterStringFromCode(c0_);
Handle<FixedArray> element = factory->NewFixedArray(1);
element->set(0, *name);
array = factory->NewJSArrayWithElements(element);
......
......@@ -3237,16 +3237,6 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_ObjectFreeze) {
}
MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate,
Object* char_code) {
if (char_code->IsNumber()) {
return isolate->heap()->LookupSingleCharacterStringFromCode(
NumberToUint32(char_code) & 0xffff);
}
return isolate->heap()->empty_string();
}
RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringCharCodeAt) {
SealHandleScope shs(isolate);
ASSERT(args.length() == 2);
......@@ -3272,9 +3262,13 @@ RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringCharCodeAt) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_CharFromCode) {
SealHandleScope shs(isolate);
HandleScope handlescope(isolate);
ASSERT(args.length() == 1);
return CharFromCode(isolate, args[0]);
if (args[0]->IsNumber()) {
uint32_t code = NumberToUint32(args[0]) & 0xffff;
return *isolate->factory()->LookupSingleCharacterStringFromCode(code);
}
return isolate->heap()->empty_string();
}
......@@ -4883,8 +4877,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_IsValidSmi) {
static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
if (index < static_cast<uint32_t>(string->length())) {
string->TryFlatten();
return LookupSingleCharacterStringFromCode(
string->GetIsolate(),
return string->GetIsolate()->factory()->LookupSingleCharacterStringFromCode(
string->Get(index));
}
return Execution::CharAt(string, index);
......@@ -6854,7 +6847,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToArray) {
}
for (int i = position; i < length; ++i) {
Handle<Object> str =
LookupSingleCharacterStringFromCode(isolate, s->Get(i));
isolate->factory()->LookupSingleCharacterStringFromCode(s->Get(i));
elements->set(i, *str);
}
......
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