Commit a87a971b authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[runtime] Inline SeqOneByteSubStringKey IsMatch and AsHandle

The performance actually matters to JSON parsing and this improves it by a % or
2.

In the longer run we should probably share the IsMatch implementation in
StringTableKey directly and call a virtual GetBytes on the key implementation.

Change-Id: I838a106f9c8c52f0385057a52a8c0b9141ae025b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1589977
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Auto-Submit: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61183}
parent 69a71cba
...@@ -6477,23 +6477,6 @@ class RegExpKey : public HashTableKey { ...@@ -6477,23 +6477,6 @@ class RegExpKey : public HashTableKey {
Smi flags_; Smi flags_;
}; };
Handle<String> SeqOneByteSubStringKey::AsHandle(Isolate* isolate) {
return isolate->factory()->NewOneByteInternalizedSubString(
string_, from_, length_, HashField());
}
bool SeqOneByteSubStringKey::IsMatch(Object object) {
DisallowHeapAllocation no_gc;
String string = String::cast(object);
if (string.length() != length_) return false;
if (string.IsOneByteRepresentation()) {
const uint8_t* data = string.GetChars<uint8_t>(no_gc);
return CompareChars(string_->GetChars(no_gc) + from_, data, length_) == 0;
}
const uint16_t* data = string.GetChars<uint16_t>(no_gc);
return CompareChars(string_->GetChars(no_gc) + from_, data, length_) == 0;
}
// InternalizedStringKey carries a string/internalized-string object as key. // InternalizedStringKey carries a string/internalized-string object as key.
class InternalizedStringKey : public StringTableKey { class InternalizedStringKey : public StringTableKey {
public: public:
......
...@@ -260,8 +260,22 @@ class SeqOneByteSubStringKey final : public StringTableKey { ...@@ -260,8 +260,22 @@ class SeqOneByteSubStringKey final : public StringTableKey {
#pragma warning(pop) #pragma warning(pop)
#endif #endif
bool IsMatch(Object string) override; bool IsMatch(Object object) override {
Handle<String> AsHandle(Isolate* isolate) override; DisallowHeapAllocation no_gc;
String string = String::cast(object);
if (string.length() != length_) return false;
if (string.IsOneByteRepresentation()) {
const uint8_t* data = string.GetChars<uint8_t>(no_gc);
return CompareChars(string_->GetChars(no_gc) + from_, data, length_) == 0;
}
const uint16_t* data = string.GetChars<uint16_t>(no_gc);
return CompareChars(string_->GetChars(no_gc) + from_, data, length_) == 0;
}
Handle<String> AsHandle(Isolate* isolate) override {
return isolate->factory()->NewOneByteInternalizedSubString(
string_, from_, length_, HashField());
}
private: private:
Handle<SeqOneByteString> string_; Handle<SeqOneByteString> string_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment