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:
Leonardo de Moura 2015-08-14 15:27:44 -07:00
parent 5a6a4b45c1
commit 54a49bbf2e

View file

@ -24,10 +24,15 @@ void finalize_serializer() {
void serializer_core::write_unsigned(unsigned i) {
static_assert(sizeof(i) == 4, "unexpected unsigned size");
m_out.put((i >> 24) & 0xff);
m_out.put((i >> 16) & 0xff);
m_out.put((i >> 8) & 0xff);
m_out.put(i & 0xff);
if (i < 255) {
m_out.put(i & 0xff);
} else {
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) {
@ -71,13 +76,17 @@ std::string deserializer_core::read_string() {
}
unsigned deserializer_core::read_unsigned() {
unsigned r;
unsigned r = static_cast<unsigned>(m_in.get());
static_assert(sizeof(r) == 4, "unexpected unsigned size");
r = static_cast<unsigned>(m_in.get()) << 24;
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;
if (r < 255) {
return r;
} else {
r = static_cast<unsigned>(m_in.get()) << 24;
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() {