From 80e72734602709d7a5508e1c18cfdc128bae840b Mon Sep 17 00:00:00 2001 From: Matt Kuruc Date: Wed, 24 Apr 2024 15:38:32 -0400 Subject: [PATCH] Utilize `string_view` initialization of `TfToken` in path parsing --- pxr/usd/sdf/pathParser.cpp | 5 +++++ pxr/usd/sdf/pathParser.h | 19 ------------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/pxr/usd/sdf/pathParser.cpp b/pxr/usd/sdf/pathParser.cpp index 409ed55451..45813c4a9a 100644 --- a/pxr/usd/sdf/pathParser.cpp +++ b/pxr/usd/sdf/pathParser.cpp @@ -30,6 +30,11 @@ using namespace PXR_PEGTL_NAMESPACE; namespace Sdf_PathParser { +template +TfToken GetToken(Input const &in) { + return TfToken{in.string_view()}; +} + template <> struct Action { template diff --git a/pxr/usd/sdf/pathParser.h b/pxr/usd/sdf/pathParser.h index 95b743fee3..8635586121 100644 --- a/pxr/usd/sdf/pathParser.h +++ b/pxr/usd/sdf/pathParser.h @@ -216,25 +216,6 @@ struct PPContext { std::string varName; }; -template -TfToken GetToken(Input const &in) { - constexpr int BufSz = 32; - char buf[BufSz]; - size_t strSize = std::distance(in.begin(), in.end()); - TfToken tok; - if (strSize < BufSz) { - // copy & null-terminate. - std::copy(in.begin(), in.end(), buf); - buf[strSize] = '\0'; - tok = TfToken(buf); - } - else { - // fall back to string path. - tok = TfToken(in.string()); - } - return tok; -} - template struct Action : PEGTL_NS::nothing {};