Optimized write calls in Serializer.

This commit is contained in:
Arron David Nelson 2024-02-17 00:27:54 -08:00
parent 54065f6ce3
commit d3c1e81a27

View File

@ -194,8 +194,7 @@ namespace ehs
Byte* r = new Byte[this->size + remainder]; Byte* r = new Byte[this->size + remainder];
for (N i = 0; i < this->size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -265,8 +264,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -336,8 +334,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -409,8 +406,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -463,8 +459,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -504,8 +499,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -545,8 +539,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -585,8 +578,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -626,8 +618,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -667,8 +658,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -707,8 +697,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -748,8 +737,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -789,8 +777,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -830,8 +817,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -871,8 +857,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;
@ -930,6 +915,26 @@ namespace ehs
offset += ser.Size(); offset += ser.Size();
} }
void WritePadding(const N size)
{
if (size > this->size - offset)
{
N remainder = size - (this->size - offset);
Byte* r = new Byte[this->size + remainder];
Util::Copy(r, data, this->size);
delete[] data;
data = r;
size += remainder;
}
Util::Zero(&data[offset], size);
offset += size;
}
template<typename T> template<typename T>
void Write(const T value) void Write(const T value)
{ {
@ -939,8 +944,7 @@ namespace ehs
Byte* r = new Byte[size + remainder]; Byte* r = new Byte[size + remainder];
for (N i = 0; i < size; ++i) Util::Copy(r, data, size);
r[i] = data[i];
delete[] data; delete[] data;
data = r; data = r;