aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/attr-set.hh
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2022-03-04 19:31:59 +0100
committerpennae <github@quasiparticle.net>2022-04-21 21:46:06 +0200
commit6526d1676ba5a645f65d751e7529ccd273579017 (patch)
tree62e94d270447a99ba7ea4a4093b6235c721f1985 /src/libexpr/attr-set.hh
parent34b72775cfe755db1bc61cb950c25759c0694be4 (diff)
replace most Pos objects/ptrs with indexes into a position table
Pos objects are somewhat wasteful as they duplicate the origin file name and input type for each object. on files that produce more than one Pos when parsed this a sizeable waste of memory (one pointer per Pos). the same goes for ptr<Pos> on 64 bit machines: parsing enough source to require 8 bytes to locate a position would need at least 8GB of input and 64GB of expression memory. it's not likely that we'll hit that any time soon, so we can use a uint32_t index to locate positions instead.
Diffstat (limited to 'src/libexpr/attr-set.hh')
-rw-r--r--src/libexpr/attr-set.hh16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/libexpr/attr-set.hh b/src/libexpr/attr-set.hh
index 1e6c548c6..23d68dda2 100644
--- a/src/libexpr/attr-set.hh
+++ b/src/libexpr/attr-set.hh
@@ -17,10 +17,10 @@ struct Attr
{
Symbol name;
Value * value;
- ptr<Pos> pos;
- Attr(Symbol name, Value * value, ptr<Pos> pos = ptr(&noPos))
+ PosIdx pos;
+ Attr(Symbol name, Value * value, PosIdx pos = noPos)
: name(name), value(value), pos(pos) { };
- Attr() : pos(&noPos) { };
+ Attr() { };
bool operator < (const Attr & a) const
{
return name < a.name;
@@ -35,13 +35,13 @@ class Bindings
{
public:
typedef uint32_t size_t;
- ptr<Pos> pos;
+ PosIdx pos;
private:
size_t size_, capacity_;
Attr attrs[0];
- Bindings(size_t capacity) : pos(&noPos), size_(0), capacity_(capacity) { }
+ Bindings(size_t capacity) : size_(0), capacity_(capacity) { }
Bindings(const Bindings & bindings) = delete;
public:
@@ -118,7 +118,7 @@ public:
: bindings(bindings), state(state)
{ }
- void insert(Symbol name, Value * value, ptr<Pos> pos = ptr(&noPos))
+ void insert(Symbol name, Value * value, PosIdx pos = noPos)
{
insert(Attr(name, value, pos));
}
@@ -133,9 +133,9 @@ public:
bindings->push_back(attr);
}
- Value & alloc(const Symbol & name, ptr<Pos> pos = ptr(&noPos));
+ Value & alloc(const Symbol & name, PosIdx pos = noPos);
- Value & alloc(std::string_view name, ptr<Pos> pos = ptr(&noPos));
+ Value & alloc(std::string_view name, PosIdx pos = noPos);
Bindings * finish()
{