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

Unified Diff: src/factory.cc

Issue 239243018: Heap::AllocateStringFromOneByte() and major part of its callers handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing comment + some cleanup 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 | « src/factory.h ('k') | 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 879b9b74ef1e1e85f63880c4038275752b6f42d5..ae2a699c793e06296c043f18dc5029cc70c990f0 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -271,16 +271,29 @@ template Handle<String> Factory::InternalizeStringWithKey<
SubStringKey<uint16_t> > (SubStringKey<uint16_t>* key);
-Handle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
- PretenureFlag pretenure) {
- CALL_HEAP_FUNCTION(
+MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
+ PretenureFlag pretenure) {
+ int length = string.length();
+ if (length == 1) {
+ return LookupSingleCharacterStringFromCode(string[0]);
+ }
+ Handle<SeqOneByteString> result;
+ ASSIGN_RETURN_ON_EXCEPTION(
isolate(),
- isolate()->heap()->AllocateStringFromOneByte(string, pretenure),
+ result,
+ NewRawOneByteString(string.length(), pretenure),
String);
+
+ DisallowHeapAllocation no_gc;
+ // Copy the characters into the new object.
+ CopyChars(SeqOneByteString::cast(*result)->GetChars(),
+ string.start(),
+ length);
+ return result;
}
-Handle<String> Factory::NewStringFromUtf8(Vector<const char> string,
- PretenureFlag pretenure) {
+MaybeHandle<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();
@@ -300,8 +313,8 @@ Handle<String> Factory::NewStringFromUtf8(Vector<const char> string,
}
-Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
- PretenureFlag pretenure) {
+MaybeHandle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
+ PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateStringFromTwoByte(string, pretenure),
@@ -1198,8 +1211,7 @@ Handle<String> Factory::EmergencyNewError(const char* message,
} else {
buffer[kBufferSize - 1] = '\0';
}
- Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED);
- return error_string;
+ return NewStringFromUtf8(CStrVector(buffer), TENURED).ToHandleChecked();
}
@@ -1956,7 +1968,7 @@ Handle<String> Factory::NumberToString(Handle<Object> number,
// We tenure the allocated string since it is referenced from the
// number-string cache which lives in the old space.
- Handle<String> js_string = NewStringFromOneByte(OneByteVector(str), TENURED);
+ Handle<String> js_string = NewStringFromAsciiChecked(str, TENURED);
SetNumberStringCache(number, js_string);
return js_string;
}
« no previous file with comments | « src/factory.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698