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

Unified Diff: src/ast/ast-value-factory.h

Issue 2220363002: De-virtualize AstString. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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 | « no previous file | src/ast/ast-value-factory.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/ast-value-factory.h
diff --git a/src/ast/ast-value-factory.h b/src/ast/ast-value-factory.h
index 9b17ba6514b498c7e0f3a78ced48727466302204..90a9a5d2bf05b12626b3f0103590cc1504a860c9 100644
--- a/src/ast/ast-value-factory.h
+++ b/src/ast/ast-value-factory.h
@@ -42,13 +42,14 @@ namespace internal {
class AstString : public ZoneObject {
public:
- virtual ~AstString() {}
+ explicit AstString(bool is_raw) : is_raw_(is_raw) {}
+ ~AstString() {}
- virtual int length() const = 0;
+ int length() const;
bool IsEmpty() const { return length() == 0; }
// Puts the string into the V8 heap.
- virtual void Internalize(Isolate* isolate) = 0;
+ void Internalize(Isolate* isolate);
// This function can be called after internalizing.
V8_INLINE Handle<String> string() const {
@@ -57,6 +58,8 @@ class AstString : public ZoneObject {
}
protected:
+ // Poor-man's virtual dispatch to AstRawString / AstConsString. But faster!
+ bool is_raw_;
Toon Verwaest 2016/08/08 09:43:24 You probably want to pack this better with fields
// This is null until the string is internalized.
Handle<String> string_;
};
@@ -64,7 +67,7 @@ class AstString : public ZoneObject {
class AstRawString final : public AstString {
public:
- int length() const override {
+ int length() const {
if (is_one_byte_)
return literal_bytes_.length();
return literal_bytes_.length() / 2;
@@ -72,7 +75,7 @@ class AstRawString final : public AstString {
int byte_length() const { return literal_bytes_.length(); }
- void Internalize(Isolate* isolate) override;
+ void Internalize(Isolate* isolate);
bool AsArrayIndex(uint32_t* index) const;
@@ -100,12 +103,13 @@ class AstRawString final : public AstString {
friend class AstRawStringInternalizationKey;
AstRawString(bool is_one_byte, const Vector<const byte>& literal_bytes,
- uint32_t hash)
- : is_one_byte_(is_one_byte), literal_bytes_(literal_bytes), hash_(hash) {}
+ uint32_t hash)
+ : AstString(true),
+ is_one_byte_(is_one_byte),
+ literal_bytes_(literal_bytes),
+ hash_(hash) {}
- AstRawString()
- : is_one_byte_(true),
- hash_(0) {}
+ AstRawString() : AstString(true), is_one_byte_(true), hash_(0) {}
bool is_one_byte_;
@@ -118,11 +122,14 @@ class AstRawString final : public AstString {
class AstConsString final : public AstString {
public:
AstConsString(const AstString* left, const AstString* right)
- : length_(left->length() + right->length()), left_(left), right_(right) {}
+ : AstString(false),
+ length_(left->length() + right->length()),
+ left_(left),
+ right_(right) {}
- int length() const override { return length_; }
+ int length() const { return length_; }
- void Internalize(Isolate* isolate) override;
+ void Internalize(Isolate* isolate);
private:
const int length_;
« no previous file with comments | « no previous file | src/ast/ast-value-factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698