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

Unified Diff: src/factory.cc

Issue 2621913002: Revert of Internalize strings in-place (Closed)
Patch Set: Created 3 years, 11 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/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 d6b770a8fbf1d33d497f38c6310ac44650fbbe31..f6c06b631642fe9d959982e6bafc712082e85a2a 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -276,7 +276,6 @@
MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
PretenureFlag pretenure) {
int length = string.length();
- if (length == 0) return empty_string();
if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);
Handle<SeqOneByteString> result;
ASSIGN_RETURN_ON_EXCEPTION(
@@ -370,7 +369,6 @@
MaybeHandle<String> Factory::NewStringFromTwoByte(const uc16* string,
int length,
PretenureFlag pretenure) {
- if (length == 0) return empty_string();
if (String::IsOneByte(string, length)) {
if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);
Handle<SeqOneByteString> result;
@@ -455,63 +453,38 @@
String);
}
-namespace {
-
-MaybeHandle<Map> GetInternalizedStringMap(Factory* f, Handle<String> string) {
- switch (string->map()->instance_type()) {
- case STRING_TYPE:
- return f->internalized_string_map();
- case ONE_BYTE_STRING_TYPE:
- return f->one_byte_internalized_string_map();
- case EXTERNAL_STRING_TYPE:
- return f->external_internalized_string_map();
- case EXTERNAL_ONE_BYTE_STRING_TYPE:
- return f->external_one_byte_internalized_string_map();
- case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
- return f->external_internalized_string_with_one_byte_data_map();
- case SHORT_EXTERNAL_STRING_TYPE:
- return f->short_external_internalized_string_map();
- case SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE:
- return f->short_external_one_byte_internalized_string_map();
- case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
- return f->short_external_internalized_string_with_one_byte_data_map();
- default: return MaybeHandle<Map>(); // No match found.
- }
-}
-
-} // namespace
MaybeHandle<Map> Factory::InternalizedStringMapForString(
Handle<String> string) {
// If the string is in new space it cannot be used as internalized.
if (isolate()->heap()->InNewSpace(*string)) return MaybeHandle<Map>();
- return GetInternalizedStringMap(this, string);
-}
-
-template <class StringClass>
-Handle<StringClass> Factory::InternalizeExternalString(Handle<String> string) {
- Handle<StringClass> cast_string = Handle<StringClass>::cast(string);
- Handle<Map> map = GetInternalizedStringMap(this, string).ToHandleChecked();
- Handle<StringClass> external_string = New<StringClass>(map, OLD_SPACE);
- external_string->set_length(cast_string->length());
- external_string->set_hash_field(cast_string->hash_field());
- external_string->set_resource(nullptr);
- isolate()->heap()->RegisterExternalString(*external_string);
- return external_string;
-}
-
-template Handle<ExternalOneByteString>
- Factory::InternalizeExternalString<ExternalOneByteString>(Handle<String>);
-template Handle<ExternalTwoByteString>
- Factory::InternalizeExternalString<ExternalTwoByteString>(Handle<String>);
+ // Find the corresponding internalized string map for strings.
+ switch (string->map()->instance_type()) {
+ case STRING_TYPE: return internalized_string_map();
+ case ONE_BYTE_STRING_TYPE:
+ return one_byte_internalized_string_map();
+ case EXTERNAL_STRING_TYPE: return external_internalized_string_map();
+ case EXTERNAL_ONE_BYTE_STRING_TYPE:
+ return external_one_byte_internalized_string_map();
+ case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
+ return external_internalized_string_with_one_byte_data_map();
+ case SHORT_EXTERNAL_STRING_TYPE:
+ return short_external_internalized_string_map();
+ case SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE:
+ return short_external_one_byte_internalized_string_map();
+ case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
+ return short_external_internalized_string_with_one_byte_data_map();
+ default: return MaybeHandle<Map>(); // No match found.
+ }
+}
+
MaybeHandle<SeqOneByteString> Factory::NewRawOneByteString(
int length, PretenureFlag pretenure) {
if (length > String::kMaxLength || length < 0) {
THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), SeqOneByteString);
}
- DCHECK(length > 0); // Use Factory::empty_string() instead.
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateRawOneByteString(length, pretenure),
@@ -524,7 +497,6 @@
if (length > String::kMaxLength || length < 0) {
THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), SeqTwoByteString);
}
- DCHECK(length > 0); // Use Factory::empty_string() instead.
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateRawTwoByteString(length, pretenure),
@@ -613,12 +585,6 @@
MaybeHandle<String> Factory::NewConsString(Handle<String> left,
Handle<String> right) {
- if (left->IsThinString()) {
- left = handle(Handle<ThinString>::cast(left)->actual(), isolate());
- }
- if (right->IsThinString()) {
- right = handle(Handle<ThinString>::cast(right)->actual(), isolate());
- }
int left_length = left->length();
if (left_length == 0) return right;
int right_length = right->length();
« no previous file with comments | « src/factory.h ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698