From d3c1e81a27e6608565c30b6065a3ed2ee4ed23fb Mon Sep 17 00:00:00 2001 From: karutoh Date: Sat, 17 Feb 2024 00:27:54 -0800 Subject: [PATCH] Optimized write calls in Serializer. --- include/ehs/Serializer.h | 68 +++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/include/ehs/Serializer.h b/include/ehs/Serializer.h index fb1b55d..147d9a5 100644 --- a/include/ehs/Serializer.h +++ b/include/ehs/Serializer.h @@ -194,8 +194,7 @@ namespace ehs Byte* r = new Byte[this->size + remainder]; - for (N i = 0; i < this->size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -265,8 +264,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -336,8 +334,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -409,8 +406,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -463,8 +459,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -504,8 +499,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -545,8 +539,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -585,8 +578,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -626,8 +618,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -667,8 +658,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -707,8 +697,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -748,8 +737,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -789,8 +777,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -830,8 +817,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -871,8 +857,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r; @@ -930,6 +915,26 @@ namespace ehs 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 void Write(const T value) { @@ -939,8 +944,7 @@ namespace ehs Byte* r = new Byte[size + remainder]; - for (N i = 0; i < size; ++i) - r[i] = data[i]; + Util::Copy(r, data, size); delete[] data; data = r;