Skip to content

Commit

Permalink
MemoryOutputStream: optimize writeBytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoltanBojthe committed Nov 22, 2024
1 parent 2b109a7 commit 3f85925
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/inet/common/MemoryOutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,7 @@ class INET_API MemoryOutputStream
ASSERT(b(0) <= offset && offset <= B(bytes.size()));
ASSERT(b(0) <= end && end <= B(bytes.size()));
ASSERT(offset <= end);
if (isByteAligned()) {
data.insert(data.end(), bytes.begin() + offset.get<B>(), bytes.begin() + end.get<B>());
this->length += end - offset;
}
else {
for (B::value_type i = offset.get<B>(); i < end.get<B>(); i++)
writeByte(bytes.at(i));
}
writeBytes(bytes.data() + offset.get<B>(), end - offset);
}

/**
Expand All @@ -194,6 +187,8 @@ class INET_API MemoryOutputStream
void writeBytes(const uint8_t *buffer, B length) {
ASSERT(buffer != nullptr);
ASSERT(B(0) <= length);
if (length == B(0))
return;
if (isByteAligned()) {
data.insert(data.end(), buffer, buffer + length.get<B>());
this->length += length;
Expand Down

0 comments on commit 3f85925

Please sign in to comment.