From 849b99d24442b8c522e914299f43d421341fe075 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Fri, 14 Aug 2015 17:56:21 -0700 Subject: [PATCH] perf(library/module): use block read --- src/library/module.cpp | 3 +-- src/util/serializer.cpp | 5 +++++ src/util/serializer.h | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/library/module.cpp b/src/library/module.cpp index 71e3fc98c..ee8ae55e9 100644 --- a/src/library/module.cpp +++ b/src/library/module.cpp @@ -367,8 +367,7 @@ struct import_modules_fn { unsigned code_size = d1.read_unsigned(); std::vector code(code_size); - for (unsigned i = 0; i < code_size; i++) - code[i] = d1.read_char(); + d1.read(code); unsigned computed_hash = hash(code_size, [&](unsigned i) { return code[i]; }); if (claimed_hash != computed_hash) diff --git a/src/util/serializer.cpp b/src/util/serializer.cpp index 27fe5db8a..12c17b9a4 100644 --- a/src/util/serializer.cpp +++ b/src/util/serializer.cpp @@ -108,4 +108,9 @@ double deserializer_core::read_double() { in >> r; return r; } + +void deserializer_core::read(std::vector & data) { + unsigned sz = data.size(); + m_in.read(data.data(), sz); +} } diff --git a/src/util/serializer.h b/src/util/serializer.h index eb40b737b..6329c95ed 100644 --- a/src/util/serializer.h +++ b/src/util/serializer.h @@ -60,6 +60,8 @@ public: char read_char() { return m_in.get(); } bool read_bool() { return m_in.get() != 0; } double read_double(); + // read data.size() bytes from input stream and store it at data + void read(std::vector & data); }; typedef extensible_object deserializer;