[compiler] Use StringToDouble without allocation
We had a way to do string to double without allocation that we were using on StringData. Reuse that on StringRef for Strings that can access the heap. BUg: v8:7790 Change-Id: I30e6dace3fbf05eb8672ff1bad46f6c6d6fe1d6d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2450013 Reviewed-by: Nico Hartmann <nicohartmann@chromium.org> Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org> Cr-Commit-Position: refs/heads/master@{#70384}
This commit is contained in:
parent
bbecd8d5b3
commit
af00c2618a
@ -845,8 +845,6 @@ class StringData : public NameData {
|
||||
// element access (s[i]). The first pair component is always less than
|
||||
// {length_}. The second component is never nullptr.
|
||||
ZoneVector<std::pair<uint32_t, ObjectData*>> chars_as_strings_;
|
||||
|
||||
static constexpr int kMaxLengthForDoubleConversion = 23;
|
||||
};
|
||||
|
||||
class SymbolData : public NameData {
|
||||
@ -857,22 +855,34 @@ class SymbolData : public NameData {
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
// String to double helper without heap allocation.
|
||||
base::Optional<double> StringToDouble(Handle<String> object) {
|
||||
const int kMaxLengthForDoubleConversion = 23;
|
||||
String string = *object;
|
||||
int length = string.length();
|
||||
if (length <= kMaxLengthForDoubleConversion) {
|
||||
const int flags = ALLOW_HEX | ALLOW_OCTAL | ALLOW_BINARY;
|
||||
uc16 buffer[kMaxLengthForDoubleConversion];
|
||||
String::WriteToFlat(*object, buffer, 0, length);
|
||||
Vector<const uc16> v(buffer, length);
|
||||
return StringToDouble(v, flags);
|
||||
}
|
||||
return base::nullopt;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
StringData::StringData(JSHeapBroker* broker, ObjectData** storage,
|
||||
Handle<String> object)
|
||||
: NameData(broker, storage, object),
|
||||
length_(object->length()),
|
||||
first_char_(length_ > 0 ? object->Get(0) : 0),
|
||||
to_number_(StringToDouble(object)),
|
||||
is_external_string_(object->IsExternalString()),
|
||||
is_seq_string_(object->IsSeqString()),
|
||||
chars_as_strings_(broker->zone()) {
|
||||
if (length_ <= kMaxLengthForDoubleConversion) {
|
||||
const int flags = ALLOW_HEX | ALLOW_OCTAL | ALLOW_BINARY;
|
||||
uc16 buffer[kMaxLengthForDoubleConversion];
|
||||
String::WriteToFlat(*object, buffer, 0, length_);
|
||||
Vector<const uc16> v(buffer, length_);
|
||||
to_number_ = StringToDouble(v, flags);
|
||||
}
|
||||
}
|
||||
chars_as_strings_(broker->zone()) {}
|
||||
|
||||
class InternalizedStringData : public StringData {
|
||||
public:
|
||||
@ -3183,10 +3193,7 @@ base::Optional<double> StringRef::ToNumber() {
|
||||
broker()->mode());
|
||||
AllowHandleAllocationIfNeeded allow_handle_allocation(data()->kind(),
|
||||
broker()->mode());
|
||||
AllowHeapAllocationIfNeeded allow_heap_allocation(data()->kind(),
|
||||
broker()->mode());
|
||||
int flags = ALLOW_HEX | ALLOW_OCTAL | ALLOW_BINARY;
|
||||
return StringToDouble(broker()->isolate(), object(), flags);
|
||||
return StringToDouble(object());
|
||||
}
|
||||
return data()->AsString()->to_number();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user