Browse Source

perf: string constructor

master
Dnomd343 8 months ago
parent
commit
b23985875a
  1. 3
      src/impl/wrapper.cc
  2. 7
      test/hash.cc
  3. 3
      test/stream.cc

3
src/impl/wrapper.cc

@ -5,8 +5,7 @@
using ::md5::impl::MD5; using ::md5::impl::MD5;
std::string MD5::Digest() const { std::string MD5::Digest() const {
std::string result {}; std::string result(32, 0x00);
result.resize(32);
auto *ptr = reinterpret_cast<const uint8_t *>(&ctx_); auto *ptr = reinterpret_cast<const uint8_t *>(&ctx_);
for (int i = 0; i < 32; ++ptr) { for (int i = 0; i < 32; ++ptr) {
result[i++] = HexTable[*ptr >> 4]; result[i++] = HexTable[*ptr >> 4];

7
test/hash.cc

@ -262,11 +262,10 @@ const std::array<std::pair<uint8_t, std::string_view>, 256> test_items {{
{0xff, "11b7aaa64c413d2f0fccf893881c46a2"}, {0xff, "11b7aaa64c413d2f0fccf893881c46a2"},
}}; }};
constexpr std::string build_test_data(uint8_t index) { std::string build_test_data(uint8_t index) {
std::string data {}; std::string data(index, 0x00);
data.reserve(index);
for (uint8_t i = 0; i < index; ++i) { for (uint8_t i = 0; i < index; ++i) {
data.push_back(static_cast<char>(i)); data[i] = static_cast<char>(i);
} }
return data; return data;
}; };

3
test/stream.cc

@ -4,8 +4,7 @@
using md5::MD5; using md5::MD5;
TEST(md5sum, stream) { TEST(md5sum, stream) {
std::string test_data {}; std::string test_data(256 * 256, 0x00); // max -> 65536
test_data.resize(256 * 256); // max -> 65536
for (uint64_t i = 0; i < test_data.size(); ++i) { for (uint64_t i = 0; i < test_data.size(); ++i) {
test_data[i] = static_cast<char>(i & 0xff); test_data[i] = static_cast<char>(i & 0xff);
} }

Loading…
Cancel
Save