17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 05:09:20 +02:00

perf(uuid): text form of an uuid made without a string stream, same output

This commit is contained in:
2026-10-06 03:35:06 +02:00
parent 3a05d0d649
commit e8c00b8a2d

View File

@@ -28,23 +28,17 @@ public:
} }
std::string to_string() const { std::string to_string() const {
std::ostringstream os; // NOTE: done by hand as the text is made for each model instance of a scenery, and a string stream took a few microseconds each
os << std::hex << std::setfill('0'); static constexpr char digits[] = "0123456789abcdef";
auto put = [&](int i){ std::string text;
os << std::setw(2) << static_cast<int>(bytes[i]); text.reserve(36);
}; // format 12-4-4-4-8, the one node names in scenery files were written with
// format 8-4-4-4-12 for (int i = 0; i < 16; ++i) {
for (int i = 0; i < 4; ++i) put(i); if (i == 6 || i == 8 || i == 10 || i == 12) text += '-';
for (int i = 4; i < 6; ++i) put(i); text += digits[bytes[i] >> 4];
os << '-'; text += digits[bytes[i] & 0x0F];
for (int i = 6; i < 8; ++i) put(i); }
os << '-'; return text;
for (int i = 8; i < 10; ++i) put(i);
os << '-';
for (int i = 10; i < 12; ++i) put(i);
os << '-';
for (int i = 12; i < 16; ++i) put(i);
return os.str();
} }
static UID from_string(const std::string& str) { static UID from_string(const std::string& str) {