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

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

Issue 2792353002: [parser/ast] Reduce memory consumption for AstConsString. (Closed)
Patch Set: Fix (and minor cleanup) Created 3 years, 8 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 8f517f5213a21c81c751c64e07045d0c9ff1a654..19452bc325864fba4ab8e618d39f91c3d9c64001 100644
--- a/src/ast/ast-value-factory.h
+++ b/src/ast/ast-value-factory.h
@@ -126,12 +126,24 @@ class AstRawString final : public ZoneObject {
class AstConsString final : public ZoneObject {
public:
- AstConsString* AddString(const AstRawString* s) {
- if (s && !s->IsEmpty()) strings_.push_back(s);
+ AstConsString* AddString(Zone* zone, const AstRawString* s) {
+ if (s->IsEmpty()) return this;
+ if (!IsEmpty()) {
+ // We're putting the new string to the head of the list, meaning
+ // the string segments will be in reverse order.
+ Segment* tmp = new (zone->New(sizeof(Segment))) Segment;
+ *tmp = segment_;
+ segment_.next = tmp;
+ }
+ segment_.string = s;
return this;
}
- bool IsEmpty() const { return strings_.empty(); }
+ bool IsEmpty() const {
+ DCHECK_IMPLIES(segment_.string == nullptr, segment_.next == nullptr);
+ DCHECK_IMPLIES(segment_.string != nullptr, !segment_.string->IsEmpty());
+ return segment_.string == nullptr;
+ }
void Internalize(Isolate* isolate);
@@ -143,7 +155,7 @@ class AstConsString final : public ZoneObject {
private:
friend class AstValueFactory;
- explicit AstConsString(Zone* zone) : next_(nullptr), strings_(zone) {}
+ AstConsString() : next_(nullptr), segment_({nullptr, nullptr}) {}
AstConsString* next() const { return next_; }
AstConsString** next_location() { return &next_; }
@@ -156,7 +168,11 @@ class AstConsString final : public ZoneObject {
String** string_;
};
- ZoneLinkedList<const AstRawString*> strings_;
+ struct Segment {
+ const AstRawString* string;
+ AstConsString::Segment* next;
+ };
+ Segment segment_;
};
enum class AstSymbol : uint8_t { kHomeObjectSymbol };
« 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