Commit 8a7e6fc3 authored by adamk's avatar adamk Committed by Commit bot

Make AstConsString::length constant-time instead of O(N)

This makes it consistent in behavior with its heap-resident equivalent.

Also some minor cleanup in the AstString class hierarchy.

BUG=v8:4595
LOG=n

Review URL: https://codereview.chromium.org/1511363002

Cr-Commit-Position: refs/heads/master@{#32733}
parent 8b3ccd80
......@@ -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_;
};
......
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