From 179824a21de1c227a7d009bf9a86030cd603d0e1 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Wed, 12 Oct 2022 14:40:26 -0700 Subject: [PATCH] Use string_view when adding nodes/generators #cleanup PiperOrigin-RevId: 480721234 --- mediapipe/framework/api2/builder.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mediapipe/framework/api2/builder.h b/mediapipe/framework/api2/builder.h index 90c43a8d5..82905d2f5 100644 --- a/mediapipe/framework/api2/builder.h +++ b/mediapipe/framework/api2/builder.h @@ -440,8 +440,9 @@ class Graph { // Creates a node of a specific type. Should be used for pure interfaces, // which do not have a built-in type string. template - Node& AddNode(const std::string& type) { - auto node = std::make_unique>(type); + Node& AddNode(absl::string_view type) { + auto node = + std::make_unique>(std::string(type.data(), type.size())); auto node_p = node.get(); nodes_.emplace_back(std::move(node)); return *node_p; @@ -449,16 +450,18 @@ class Graph { // Creates a generic node, with no compile-time checking of inputs and // outputs. This can be used for calculators whose contract is not visible. - GenericNode& AddNode(const std::string& type) { - auto node = std::make_unique(type); + GenericNode& AddNode(absl::string_view type) { + auto node = + std::make_unique(std::string(type.data(), type.size())); auto node_p = node.get(); nodes_.emplace_back(std::move(node)); return *node_p; } // For legacy PacketGenerators. - PacketGenerator& AddPacketGenerator(const std::string& type) { - auto node = std::make_unique(type); + PacketGenerator& AddPacketGenerator(absl::string_view type) { + auto node = std::make_unique( + std::string(type.data(), type.size())); auto node_p = node.get(); packet_gens_.emplace_back(std::move(node)); return *node_p;