Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(911)

Unified Diff: src/runtime.cc

Issue 11348349: Improve array to string conversion. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 5106be81bbd70d73006507baee098e265f60415d..4526b07171653ed5399dd8b3479654282965459e 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -5063,46 +5063,25 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToNumber) {
}
-RUNTIME_FUNCTION(MaybeObject*, Runtime_StringFromCharCodeArray) {
- NoHandleAllocation ha;
- ASSERT(args.length() == 1);
-
- CONVERT_ARG_CHECKED(JSArray, codes, 0);
- int length = Smi::cast(codes->length())->value();
-
- // Check if the string can be ASCII.
- int i;
- for (i = 0; i < length; i++) {
- Object* element;
- { MaybeObject* maybe_element = codes->GetElement(i);
- // We probably can't get an exception here, but just in order to enforce
- // the checking of inputs in the runtime calls we check here.
- if (!maybe_element->ToObject(&element)) return maybe_element;
- }
- CONVERT_NUMBER_CHECKED(int, chr, Int32, element);
- if ((chr & 0xffff) > String::kMaxAsciiCharCode)
- break;
+RUNTIME_FUNCTION(MaybeObject*, Runtime_NewString) {
+ CONVERT_SMI_ARG_CHECKED(length, 0);
+ CONVERT_BOOLEAN_ARG_CHECKED(is_one_byte, 1);
+ if (length == 0) return isolate->heap()->empty_string();
+ if (is_one_byte) {
+ return isolate->heap()->AllocateRawOneByteString(length);
+ } else {
+ return isolate->heap()->AllocateRawTwoByteString(length);
}
+}
- MaybeObject* maybe_object = NULL;
- if (i == length) { // The string is ASCII.
- maybe_object = isolate->heap()->AllocateRawOneByteString(length);
- } else { // The string is not ASCII.
- maybe_object = isolate->heap()->AllocateRawTwoByteString(length);
- }
- Object* object = NULL;
- if (!maybe_object->ToObject(&object)) return maybe_object;
- String* result = String::cast(object);
- for (int i = 0; i < length; i++) {
- Object* element;
- { MaybeObject* maybe_element = codes->GetElement(i);
- if (!maybe_element->ToObject(&element)) return maybe_element;
- }
- CONVERT_NUMBER_CHECKED(int, chr, Int32, element);
- result->Set(i, chr & 0xffff);
- }
- return result;
+RUNTIME_FUNCTION(MaybeObject*, Runtime_TruncateString) {
+ CONVERT_ARG_CHECKED(SeqString, string, 0);
+ CONVERT_SMI_ARG_CHECKED(new_length, 1);
+ RUNTIME_ASSERT(new_length <= string->length());
+ RUNTIME_ASSERT(new_length > 0);
+ if (new_length != string->length()) string->Truncate(new_length);
+ return string;
}

Powered by Google App Engine
This is Rietveld 408576698