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

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

Issue 1511363002: Make AstConsString::length constant-time instead of O(N) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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 | no next file » | 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 7b34a6b5649f0227b6ab354ab15b3dbb62957d7a..ec9a8e389fb18cd6f0b6ea53b13061a6cbdebd4a 100644
--- a/src/ast/ast-value-factory.h
+++ b/src/ast/ast-value-factory.h
@@ -62,7 +62,7 @@ class AstString : public ZoneObject {
};
-class AstRawString : public AstString {
+class AstRawString final : public AstString {
public:
int length() const override {
if (is_one_byte_)
@@ -115,19 +115,17 @@ class AstRawString : public AstString {
};
-class AstConsString : public AstString {
+class AstConsString final : public AstString {
public:
AstConsString(const AstString* left, const AstString* right)
- : left_(left),
- right_(right) {}
+ : length_(left->length() + right->length()), left_(left), right_(right) {}
- int length() const override { return left_->length() + right_->length(); }
+ int length() const override { return length_; }
void Internalize(Isolate* isolate) override;
private:
- friend class AstValueFactory;
-
+ const int length_;
const AstString* left_;
const AstString* right_;
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698