Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2884dd8b authored by Steven Moreland's avatar Steven Moreland
Browse files

binder_parcel_fuzzer: faster string creation

Bug: 142473153
Test: binder_parcel_fuzzer execution time reduced by an order of
    magnitude for some extreme cases

Change-Id: I0f4a50be4260f968e31068407bc0a7b70ae33a3d
parent dc449dc7
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -24,13 +24,17 @@
std::string hexString(const void* bytes, size_t len) {
    if (bytes == nullptr) return "<null>";

    std::ostringstream s;
    s << std::hex << std::setfill('0');
    const uint8_t* bytes8 = static_cast<const uint8_t*>(bytes);
    char chars[] = "0123456789abcdef";
    std::string result;
    result.resize(len * 2);

    for (size_t i = 0; i < len; i++) {
        s << std::setw(2) << static_cast<int>(
            static_cast<const uint8_t*>(bytes)[i]);
        result[2 * i] = chars[bytes8[i] >> 4];
        result[2 * i + 1] = chars[bytes8[i] & 0xf];
    }
    return s.str();

    return result;
}
std::string hexString(const std::vector<uint8_t>& bytes) {
    return hexString(bytes.data(), bytes.size());