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

Unified Diff: src/factory.cc

Issue 239083005: Callers of Heap::AllocateStringFromOneByte() and Heap::AllocateStringFromUtf8() handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing review comments Created 6 years, 8 months 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
« no previous file with comments | « no previous file | src/heap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index aec56bf232effb1d2d2395f9358c186b77f0f047..1330317cf2aa640f65d01e26d60074da843bfa33 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -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);
}
« no previous file with comments | « no previous file | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698