refactor: faster chunk & schematic loading

This commit is contained in:
JuiceyDev
2026-04-03 20:40:21 +02:00
parent 342a195ba8
commit 4dfba6ccd8
4 changed files with 128 additions and 21 deletions

View File

@@ -20,6 +20,8 @@ public:
ByteArrayInputStream(std::vector<uint8_t>& buf, unsigned int offset,
unsigned int length);
ByteArrayInputStream(std::vector<uint8_t>& buf);
// takes ownership of the vector
ByteArrayInputStream(std::vector<uint8_t>&& buf);
virtual ~ByteArrayInputStream();
virtual int read();
virtual int read(std::vector<uint8_t>& b);
@@ -36,4 +38,4 @@ public:
mark = 0;
pos = 0;
}
};
};

View File

@@ -28,6 +28,11 @@ ByteArrayInputStream::ByteArrayInputStream(std::vector<uint8_t>& buf)
this->buf = buf;
}
// 4jcraft: helper function to create a ByteArrayInputStream from a vector of bytes to avoid one copy
ByteArrayInputStream::ByteArrayInputStream(std::vector<uint8_t>&& buf)
: buf(std::move(buf)), pos(0), count(this->buf.size()), mark(0) {
}
// Reads the next byte of data from this input stream. The value byte is
// returned as an int in the range 0 to 255. If no byte is available because the
// end of the stream has been reached, the value -1 is returned. This read