diff --git a/src/objects-inl.h b/src/objects-inl.h index 9a65e1675d..9172257e6d 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -3581,6 +3581,22 @@ ConsString* String::VisitFlat(Visitor* visitor, } +template <> +inline Vector String::GetCharVector() { + String::FlatContent flat = GetFlatContent(); + DCHECK(flat.IsOneByte()); + return flat.ToOneByteVector(); +} + + +template <> +inline Vector String::GetCharVector() { + String::FlatContent flat = GetFlatContent(); + DCHECK(flat.IsTwoByte()); + return flat.ToUC16Vector(); +} + + uint16_t SeqOneByteString::SeqOneByteStringGet(int index) { DCHECK(index >= 0 && index < length()); return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); diff --git a/src/objects.cc b/src/objects.cc index 82ff09b317..5262ed6567 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -8298,22 +8298,6 @@ String::FlatContent String::GetFlatContent() { } -template <> -Vector String::GetCharVector() { - String::FlatContent flat = GetFlatContent(); - DCHECK(flat.IsOneByte()); - return flat.ToOneByteVector(); -} - - -template <> -Vector String::GetCharVector() { - String::FlatContent flat = GetFlatContent(); - DCHECK(flat.IsTwoByte()); - return flat.ToUC16Vector(); -} - - SmartArrayPointer String::ToCString(AllowNullsFlag allow_nulls, RobustnessFlag robust_flag, int offset, diff --git a/src/objects.h b/src/objects.h index 502d263fc9..664a5064c7 100644 --- a/src/objects.h +++ b/src/objects.h @@ -8815,7 +8815,7 @@ class String: public Name { }; template - Vector GetCharVector(); + INLINE(Vector GetCharVector()); // Get and set the length of the string. inline int length() const; diff --git a/src/runtime/runtime-uri.cc b/src/runtime/runtime-uri.cc index 16e80b5796..477071ac78 100644 --- a/src/runtime/runtime-uri.cc +++ b/src/runtime/runtime-uri.cc @@ -14,26 +14,6 @@ namespace v8 { namespace internal { -template -static INLINE(Vector GetCharVector(Handle string)); - - -template <> -Vector GetCharVector(Handle string) { - String::FlatContent flat = string->GetFlatContent(); - DCHECK(flat.IsOneByte()); - return flat.ToOneByteVector(); -} - - -template <> -Vector GetCharVector(Handle string) { - String::FlatContent flat = string->GetFlatContent(); - DCHECK(flat.IsTwoByte()); - return flat.ToUC16Vector(); -} - - class URIUnescape : public AllStatic { public: template @@ -72,7 +52,7 @@ MaybeHandle URIUnescape::Unescape(Isolate* isolate, { DisallowHeapAllocation no_allocation; StringSearch search(isolate, STATIC_CHAR_VECTOR("%")); - index = search.Search(GetCharVector(source), 0); + index = search.Search(source->GetCharVector(), 0); if (index < 0) return source; } return UnescapeSlow(isolate, source, index); @@ -89,7 +69,7 @@ MaybeHandle URIUnescape::UnescapeSlow(Isolate* isolate, int unescaped_length = 0; { DisallowHeapAllocation no_allocation; - Vector vector = GetCharVector(string); + Vector vector = string->GetCharVector(); for (int i = start_index; i < length; unescaped_length++) { int step; if (UnescapeChar(vector, i, length, &step) > @@ -112,7 +92,7 @@ MaybeHandle URIUnescape::UnescapeSlow(Isolate* isolate, ->NewRawOneByteString(unescaped_length) .ToHandleChecked(); DisallowHeapAllocation no_allocation; - Vector vector = GetCharVector(string); + Vector vector = string->GetCharVector(); for (int i = start_index; i < length; dest_position++) { int step; dest->SeqOneByteStringSet(dest_position, @@ -125,7 +105,7 @@ MaybeHandle URIUnescape::UnescapeSlow(Isolate* isolate, ->NewRawTwoByteString(unescaped_length) .ToHandleChecked(); DisallowHeapAllocation no_allocation; - Vector vector = GetCharVector(string); + Vector vector = string->GetCharVector(); for (int i = start_index; i < length; dest_position++) { int step; dest->SeqTwoByteStringSet(dest_position, @@ -221,7 +201,7 @@ MaybeHandle URIEscape::Escape(Isolate* isolate, Handle string) { { DisallowHeapAllocation no_allocation; - Vector vector = GetCharVector(string); + Vector vector = string->GetCharVector(); for (int i = 0; i < length; i++) { uint16_t c = vector[i]; if (c >= 256) { @@ -249,7 +229,7 @@ MaybeHandle URIEscape::Escape(Isolate* isolate, Handle string) { { DisallowHeapAllocation no_allocation; - Vector vector = GetCharVector(string); + Vector vector = string->GetCharVector(); for (int i = 0; i < length; i++) { uint16_t c = vector[i]; if (c >= 256) {