Skip to content

Commit

Permalink
Merge branch 'topic/bbannier/issue-1571'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Oct 13, 2023
2 parents 4970368 + 625a607 commit eda2373
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
15 changes: 15 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
1.9.0-dev.144 | 2023-10-13 11:47:35 +0200

* GH-1571: Remove trimming inside individual chunks. (Benjamin Bannier, Corelight)

Trimming `Chunk`s (always from the left) causes a lot of internal work
with only limited benefit since we manage visibility with `stream::View`s
on top of `Chunk`s anyway.

This patch removes trimming inside `Chunk`s so now any trimming only
removes `Chunk`s from `Chain`s, but does not internally change
individual `Chunk`s anymore. This might lead to slightly increased memory
use, but callers usually have that data in memory anyway.

Closes #1571.

1.9.0-dev.142 | 2023-10-09 11:10:35 +0200

* Explicitly set ASM compiler. (Benjamin Bannier, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.0-dev.142
1.9.0-dev.144
2 changes: 0 additions & 2 deletions hilti/runtime/include/types/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ class Chunk {
// only from chain so that it can track any changes.
friend class Chain;

void trim(const Offset& o);

// Update offset for current chunk and all others linked from it.
void setOffset(Offset o) {
auto c = this;
Expand Down
21 changes: 1 addition & 20 deletions hilti/runtime/src/types/stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,6 @@ Chunk::Chunk(const Offset& offset, const std::string& s) : _offset(offset) {
}
}

void Chunk::trim(const Offset& o) {
assert(o >= _offset && o < _offset + size());
if ( auto a = std::get_if<Array>(&_data) ) {
auto begin = a->second.data() + (o - _offset).Ref();
auto end = a->second.data() + a->first.Ref();
a->first = (end - begin);
memmove(a->second.data(), begin, a->first.Ref());
}
else if ( std::holds_alternative<Vector>(_data) ) {
auto& v = std::get<Vector>(_data);
v.erase(v.begin(), v.begin() + static_cast<Vector::difference_type>((o - _offset).Ref()));
}
// Nothing to do for gap chunks.

_offset = o;
}

void Chain::append(std::unique_ptr<Chunk> chunk) {
_ensureValid();
_ensureMutable();
Expand Down Expand Up @@ -117,8 +100,7 @@ void Chain::trim(const Offset& offset) {
}

else if ( _head->inRange(offset) ) {
_head->trim(offset);
assert(_head->offset() == offset);
// Perform no trimming inside individual chunks.
break;
}

Expand All @@ -128,7 +110,6 @@ void Chain::trim(const Offset& offset) {
}

_head_offset = offset;
assert(! _head || _head->offset() == offset);
}

ChainPtr Chain::deepCopy() const {
Expand Down

0 comments on commit eda2373

Please sign in to comment.