From d0f43bf582fc2dc0f0e1300cce5b8dfa7a466082 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Thu, 25 Jan 2024 14:30:56 -0800 Subject: [PATCH] Avoid another string construction --- mvt.cpp | 6 +++++- mvt.hpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mvt.cpp b/mvt.cpp index 43c29dad..16481015 100644 --- a/mvt.cpp +++ b/mvt.cpp @@ -159,7 +159,11 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) { case 1: /* string */ value.type = mvt_string; value.s = string_pool; - value.set_string_value(value_reader.get_string()); + { + auto v = value_reader.get_view(); + std::string_view sv(v.data(), v.size()); + value.set_string_value(sv); + } break; case 2: /* float */ diff --git a/mvt.hpp b/mvt.hpp index 3967d6e9..ba0d5d57 100644 --- a/mvt.hpp +++ b/mvt.hpp @@ -105,7 +105,7 @@ struct mvt_value { return s->c_str() + numeric_value.string_value.off; } - void set_string_value(const std::string &val) { + void set_string_value(const std::string_view &val) { if (s == nullptr) { s = std::make_shared(); }