feat(util/serializer): simple compression trick
reduces the standard library .olean files from 7.2 Mb to 6.1 Mb
This commit is contained in:
parent
5a6a4b45c1
commit
54a49bbf2e
1 changed files with 19 additions and 10 deletions
|
@ -24,10 +24,15 @@ void finalize_serializer() {
|
||||||
|
|
||||||
void serializer_core::write_unsigned(unsigned i) {
|
void serializer_core::write_unsigned(unsigned i) {
|
||||||
static_assert(sizeof(i) == 4, "unexpected unsigned size");
|
static_assert(sizeof(i) == 4, "unexpected unsigned size");
|
||||||
m_out.put((i >> 24) & 0xff);
|
if (i < 255) {
|
||||||
m_out.put((i >> 16) & 0xff);
|
m_out.put(i & 0xff);
|
||||||
m_out.put((i >> 8) & 0xff);
|
} else {
|
||||||
m_out.put(i & 0xff);
|
m_out.put(0xff);
|
||||||
|
m_out.put((i >> 24) & 0xff);
|
||||||
|
m_out.put((i >> 16) & 0xff);
|
||||||
|
m_out.put((i >> 8) & 0xff);
|
||||||
|
m_out.put(i & 0xff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void serializer_core::write_uint64(uint64 i) {
|
void serializer_core::write_uint64(uint64 i) {
|
||||||
|
@ -71,13 +76,17 @@ std::string deserializer_core::read_string() {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned deserializer_core::read_unsigned() {
|
unsigned deserializer_core::read_unsigned() {
|
||||||
unsigned r;
|
unsigned r = static_cast<unsigned>(m_in.get());
|
||||||
static_assert(sizeof(r) == 4, "unexpected unsigned size");
|
static_assert(sizeof(r) == 4, "unexpected unsigned size");
|
||||||
r = static_cast<unsigned>(m_in.get()) << 24;
|
if (r < 255) {
|
||||||
r |= static_cast<unsigned>(m_in.get()) << 16;
|
return r;
|
||||||
r |= static_cast<unsigned>(m_in.get()) << 8;
|
} else {
|
||||||
r |= static_cast<unsigned>(m_in.get());
|
r = static_cast<unsigned>(m_in.get()) << 24;
|
||||||
return r;
|
r |= static_cast<unsigned>(m_in.get()) << 16;
|
||||||
|
r |= static_cast<unsigned>(m_in.get()) << 8;
|
||||||
|
r |= static_cast<unsigned>(m_in.get());
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 deserializer_core::read_uint64() {
|
uint64 deserializer_core::read_uint64() {
|
||||||
|
|
Loading…
Reference in a new issue