Reviewers: Igor Sheludko,

Description:
Handlify LookupSingleCharacterStringFromCode.

[email protected]

Please review this at https://codereview.chromium.org/227593004/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+21, -31 lines):
  M src/factory.h
  M src/factory.cc
  M src/handles.h
  M src/handles.cc
  M src/hydrogen-instructions.cc
  M src/json-parser.h
  M src/runtime.cc


Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index d3a69744d2d7250a2666af9312c9104cbb9b7b32..d4909a7c1ba13280faf34c02a8cbc07e94d56c56 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -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
Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index c1b7ba72515296913a3dad735ca6516b91476502..53f55d3aacc0feed8114a466b6d00a46686e6800 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -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);
Index: src/handles.cc
diff --git a/src/handles.cc b/src/handles.cc
index b3052ad6a82fd635cdcac6d27db3aef1a282c410..7ed7c8e80f921ae7d49a54c276f0c9caa02375d3 100644
--- a/src/handles.cc
+++ b/src/handles.cc
@@ -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
Index: src/handles.h
diff --git a/src/handles.h b/src/handles.h
index 3f6040421220fb064f4ce3180c95ae8f31074dbd..edeb27b5106c02edbf73d8c82e3a129293c4f832 100644
--- a/src/handles.h
+++ b/src/handles.h
@@ -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);
Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index b54656c075c781e315237be83fff4af27efbb4c9..4f728c6f7b0af1b6629e2571218cd755fac517b6 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -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());
     }
Index: src/json-parser.h
diff --git a/src/json-parser.h b/src/json-parser.h
index a566402c7362e49928bc79a9c26ea2fd9b4dd715..5d67ae2a9a66ab716bd9ff0ee8c1ec8b01155915 100644
--- a/src/json-parser.h
+++ b/src/json-parser.h
@@ -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);
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 9410a38b32b373755d14614a5076afaf244b2f1a..d13f33d4eeded07eedb2e4969cb1a5df1bca1391 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -3254,16 +3254,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);
@@ -3289,9 +3279,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();
 }


@@ -4900,8 +4894,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);
@@ -6871,7 +6864,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);
   }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to