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;