From d2d1ff565c1f89051aac518ce5639acb1a936c2f Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 11 Nov 2023 10:38:44 +0100 Subject: [PATCH] Avoid conversions from std::string to char* to std::string Signed-off-by: Stefan Weil --- src/lstm/maxpool.cpp | 2 +- src/lstm/maxpool.h | 3 +-- src/lstm/network.cpp | 12 ++++++------ src/lstm/parallel.cpp | 2 +- src/lstm/parallel.h | 2 +- src/lstm/reconfig.cpp | 2 +- src/lstm/reconfig.h | 2 +- src/lstm/series.cpp | 2 +- src/lstm/series.h | 2 +- src/lstm/tfnetwork.cpp | 2 +- src/lstm/tfnetwork.h | 2 +- 11 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/lstm/maxpool.cpp b/src/lstm/maxpool.cpp index c097f59d..ccd5f9b9 100644 --- a/src/lstm/maxpool.cpp +++ b/src/lstm/maxpool.cpp @@ -19,7 +19,7 @@ namespace tesseract { -Maxpool::Maxpool(const char *name, int ni, int x_scale, int y_scale) +Maxpool::Maxpool(const std::string &name, int ni, int x_scale, int y_scale) : Reconfig(name, ni, x_scale, y_scale) { type_ = NT_MAXPOOL; no_ = ni; diff --git a/src/lstm/maxpool.h b/src/lstm/maxpool.h index eee3f08f..bf0110fd 100644 --- a/src/lstm/maxpool.h +++ b/src/lstm/maxpool.h @@ -2,7 +2,6 @@ // File: maxpool.h // Description: Standard Max-Pooling layer. // Author: Ray Smith -// Created: Tue Mar 18 16:28:18 PST 2014 // // (C) Copyright 2014, Google Inc. // Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,7 +28,7 @@ namespace tesseract { class Maxpool : public Reconfig { public: TESS_API - Maxpool(const char *name, int ni, int x_scale, int y_scale); + Maxpool(const std::string &name, int ni, int x_scale, int y_scale); ~Maxpool() override = default; // Accessors. diff --git a/src/lstm/network.cpp b/src/lstm/network.cpp index c714439d..6e13e496 100644 --- a/src/lstm/network.cpp +++ b/src/lstm/network.cpp @@ -264,7 +264,7 @@ Network *Network::CreateFromFile(TFile *fp) { network = new LSTM(name, ni, no, no, false, type); break; case NT_MAXPOOL: - network = new Maxpool(name.c_str(), ni, 0, 0); + network = new Maxpool(name, ni, 0, 0); break; // All variants of Parallel. case NT_PARALLEL: @@ -272,10 +272,10 @@ Network *Network::CreateFromFile(TFile *fp) { case NT_PAR_RL_LSTM: case NT_PAR_UD_LSTM: case NT_PAR_2D_LSTM: - network = new Parallel(name.c_str(), type); + network = new Parallel(name, type); break; case NT_RECONFIG: - network = new Reconfig(name.c_str(), ni, 0, 0); + network = new Reconfig(name, ni, 0, 0); break; // All variants of reversed. case NT_XREVERSED: @@ -284,11 +284,11 @@ Network *Network::CreateFromFile(TFile *fp) { network = new Reversed(name, type); break; case NT_SERIES: - network = new Series(name.c_str()); + network = new Series(name); break; case NT_TENSORFLOW: #ifdef INCLUDE_TENSORFLOW - network = new TFNetwork(name.c_str()); + network = new TFNetwork(name); #else tprintf("TensorFlow not compiled in! -DINCLUDE_TENSORFLOW\n"); #endif @@ -302,7 +302,7 @@ Network *Network::CreateFromFile(TFile *fp) { case NT_LOGISTIC: case NT_POSCLIP: case NT_SYMCLIP: - network = new FullyConnected(name.c_str(), ni, no, type); + network = new FullyConnected(name, ni, no, type); break; default: break; diff --git a/src/lstm/parallel.cpp b/src/lstm/parallel.cpp index 2713314c..83ac0eb1 100644 --- a/src/lstm/parallel.cpp +++ b/src/lstm/parallel.cpp @@ -31,7 +31,7 @@ namespace tesseract { // ni_ and no_ will be set by AddToStack. -Parallel::Parallel(const char *name, NetworkType type) : Plumbing(name) { +Parallel::Parallel(const std::string &name, NetworkType type) : Plumbing(name) { type_ = type; } diff --git a/src/lstm/parallel.h b/src/lstm/parallel.h index 0706493c..0d7ce094 100644 --- a/src/lstm/parallel.h +++ b/src/lstm/parallel.h @@ -27,7 +27,7 @@ class Parallel : public Plumbing { public: // ni_ and no_ will be set by AddToStack. TESS_API - Parallel(const char *name, NetworkType type); + Parallel(const std::string &name, NetworkType type); // Returns the shape output from the network given an input shape (which may // be partially unknown ie zero). diff --git a/src/lstm/reconfig.cpp b/src/lstm/reconfig.cpp index 4b416206..2f49d63e 100644 --- a/src/lstm/reconfig.cpp +++ b/src/lstm/reconfig.cpp @@ -20,7 +20,7 @@ namespace tesseract { -Reconfig::Reconfig(const char *name, int ni, int x_scale, int y_scale) +Reconfig::Reconfig(const std::string &name, int ni, int x_scale, int y_scale) : Network(NT_RECONFIG, name, ni, ni * x_scale * y_scale) , x_scale_(x_scale) , y_scale_(y_scale) {} diff --git a/src/lstm/reconfig.h b/src/lstm/reconfig.h index e2c6a10a..2c35f091 100644 --- a/src/lstm/reconfig.h +++ b/src/lstm/reconfig.h @@ -31,7 +31,7 @@ namespace tesseract { class Reconfig : public Network { public: TESS_API - Reconfig(const char *name, int ni, int x_scale, int y_scale); + Reconfig(const std::string &name, int ni, int x_scale, int y_scale); ~Reconfig() override = default; // Returns the shape output from the network given an input shape (which may diff --git a/src/lstm/series.cpp b/src/lstm/series.cpp index 3a1ed098..99069861 100644 --- a/src/lstm/series.cpp +++ b/src/lstm/series.cpp @@ -25,7 +25,7 @@ namespace tesseract { // ni_ and no_ will be set by AddToStack. -Series::Series(const char *name) : Plumbing(name) { +Series::Series(const std::string &name) : Plumbing(name) { type_ = NT_SERIES; } diff --git a/src/lstm/series.h b/src/lstm/series.h index 6d9965f4..fc63f284 100644 --- a/src/lstm/series.h +++ b/src/lstm/series.h @@ -27,7 +27,7 @@ class Series : public Plumbing { public: // ni_ and no_ will be set by AddToStack. TESS_API - explicit Series(const char *name); + explicit Series(const std::string &name); ~Series() override = default; // Returns the shape output from the network given an input shape (which may diff --git a/src/lstm/tfnetwork.cpp b/src/lstm/tfnetwork.cpp index 29d05ef4..d7b1441e 100644 --- a/src/lstm/tfnetwork.cpp +++ b/src/lstm/tfnetwork.cpp @@ -29,7 +29,7 @@ using tensorflow::TensorShape; namespace tesseract { -TFNetwork::TFNetwork(const char *name) : Network(NT_TENSORFLOW, name, 0, 0) {} +TFNetwork::TFNetwork(const std::string &name) : Network(NT_TENSORFLOW, name, 0, 0) {} int TFNetwork::InitFromProtoStr(const std::string &proto_str) { if (!model_proto_.ParseFromString(proto_str)) diff --git a/src/lstm/tfnetwork.h b/src/lstm/tfnetwork.h index 1ee6aeb8..7fbd6042 100644 --- a/src/lstm/tfnetwork.h +++ b/src/lstm/tfnetwork.h @@ -34,7 +34,7 @@ namespace tesseract { class TFNetwork : public Network { public: - explicit TFNetwork(const char *name); + explicit TFNetwork(const std::string &name); virtual ~TFNetwork() = default; // Returns the required shape input to the network.