diff --git a/tensorflow/core/graph/edgeset.cc b/tensorflow/core/graph/edgeset.cc index 2e0c6714616..e3b88994b5e 100644 --- a/tensorflow/core/graph/edgeset.cc +++ b/tensorflow/core/graph/edgeset.cc @@ -38,9 +38,8 @@ std::pair EdgeSet::insert(value_type value) { } // array is full. convert to set. s = new std::set; - for (int i = 0; i < kInline; i++) { - s->insert(static_cast(ptrs_[i])); - } + s->insert(reinterpret_cast(std::begin(ptrs_)), + reinterpret_cast(std::end(ptrs_))); ptrs_[0] = this; ptrs_[1] = s; // fall through. diff --git a/tensorflow/core/graph/graph_constructor.cc b/tensorflow/core/graph/graph_constructor.cc index f6d83d5f6ff..ac1b690df31 100644 --- a/tensorflow/core/graph/graph_constructor.cc +++ b/tensorflow/core/graph/graph_constructor.cc @@ -35,6 +35,8 @@ limitations under the License. #include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/tensor_id.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/gtl/flatmap.h" +#include "tensorflow/core/lib/gtl/flatset.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/lib/strings/scanner.h" #include "tensorflow/core/lib/strings/str_util.h" @@ -268,22 +270,20 @@ class GraphConstructor { int gdef_index; Node* node; // nullptr until the NodeDef is converted to a Node. }; - // TODO(vrv): Profile this data structure to see if we should use an - // alternative implementation of std::unordered_map. - std::unordered_map gdef_nodes_; + gtl::FlatMap gdef_nodes_; // Prefixes already used in the GraphDef being imported. - std::unordered_set gdef_prefixes_; + gtl::FlatSet gdef_prefixes_; // Mapping from node name to the existing node in g_. - std::unordered_map existing_nodes_; + gtl::FlatMap existing_nodes_; // Prefixes already used in the graph. - std::unordered_set existing_prefixes_; + gtl::FlatSet existing_prefixes_; // Imported node names that have been uniquified. The key is the original // name, the value is the new unique name. - std::unordered_map uniquified_names_; + gtl::FlatMap uniquified_names_; // Index of NodeDefs in node_defs_ with all inputs already converted. We use a // (sorted) set so nodes are created in the order defined in the GraphDef. @@ -360,7 +360,7 @@ bool NodeNameInValues(const std::vector& control_dependencies, // Adds any prefixes of `node_name` (not including the full name itself) to // `prefixes`. void AddPrefixes(StringPiece node_name, - std::unordered_set* prefixes) { + gtl::FlatSet* prefixes) { size_t idx = -1; while ((idx = node_name.find('/', idx + 1)) != StringPiece::npos) { prefixes->insert(node_name.substr(0, idx)); @@ -857,7 +857,7 @@ void GraphConstructor::UpdateUniquifiedColocationNames() { for (int i = 0; i < coloc_values.size(); ++i) { StringPiece val(coloc_values[i]); if (str_util::ConsumePrefix(&val, kColocationGroupPrefix)) { - const auto& name_pair = uniquified_names_.find(string(val)); + auto name_pair = uniquified_names_.find(string(val)); if (name_pair == uniquified_names_.end()) continue; updated = true; coloc_values[i] =