diff --git a/sherpa-onnx/csrc/jieba-lexicon.cc b/sherpa-onnx/csrc/jieba-lexicon.cc index 82b45cdfe..e62324103 100644 --- a/sherpa-onnx/csrc/jieba-lexicon.cc +++ b/sherpa-onnx/csrc/jieba-lexicon.cc @@ -102,13 +102,13 @@ class JiebaLexicon::Impl { this_sentence.push_back(blank); if (w == "。" || w == "!" || w == "?" || w == ",") { - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); this_sentence = {}; } } // for (const auto &w : words) if (!this_sentence.empty()) { - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); } return ans; diff --git a/sherpa-onnx/csrc/lexicon.cc b/sherpa-onnx/csrc/lexicon.cc index c635f7ffd..24184f180 100644 --- a/sherpa-onnx/csrc/lexicon.cc +++ b/sherpa-onnx/csrc/lexicon.cc @@ -253,7 +253,7 @@ std::vector Lexicon::ConvertTextToTokenIdsChinese( if (eos != -1) { this_sentence.push_back(eos); } - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); this_sentence = {}; if (sil != -1) { @@ -283,7 +283,7 @@ std::vector Lexicon::ConvertTextToTokenIdsChinese( if (eos != -1) { this_sentence.push_back(eos); } - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); return ans; } @@ -324,7 +324,7 @@ std::vector Lexicon::ConvertTextToTokenIdsNotChinese( if (w != ",") { this_sentence.push_back(blank); - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); this_sentence = {}; } @@ -348,7 +348,7 @@ std::vector Lexicon::ConvertTextToTokenIdsNotChinese( } if (!this_sentence.empty()) { - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); } return ans; diff --git a/sherpa-onnx/csrc/melo-tts-lexicon.cc b/sherpa-onnx/csrc/melo-tts-lexicon.cc index b213c4516..561aaa276 100644 --- a/sherpa-onnx/csrc/melo-tts-lexicon.cc +++ b/sherpa-onnx/csrc/melo-tts-lexicon.cc @@ -91,7 +91,6 @@ class MeloTtsLexicon::Impl { std::vector ans; TokenIDs this_sentence; - int32_t blank = token2id_.at("_"); for (const auto &w : words) { auto ids = ConvertWordToIds(w); if (ids.tokens.empty()) { diff --git a/sherpa-onnx/csrc/offline-tts-character-frontend.cc b/sherpa-onnx/csrc/offline-tts-character-frontend.cc index c92240581..72481e094 100644 --- a/sherpa-onnx/csrc/offline-tts-character-frontend.cc +++ b/sherpa-onnx/csrc/offline-tts-character-frontend.cc @@ -136,7 +136,7 @@ std::vector OfflineTtsCharacterFrontend::ConvertTextToTokenIds( this_sentence.push_back(eos_id); } - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); this_sentence = {}; // re-initialize this_sentence @@ -152,7 +152,7 @@ std::vector OfflineTtsCharacterFrontend::ConvertTextToTokenIds( } if (static_cast(this_sentence.size()) > 1 + use_eos_bos) { - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); } } else { // not adding blank @@ -171,7 +171,7 @@ std::vector OfflineTtsCharacterFrontend::ConvertTextToTokenIds( this_sentence.push_back(eos_id); } - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); this_sentence = {}; // re-initialize this_sentence @@ -182,7 +182,7 @@ std::vector OfflineTtsCharacterFrontend::ConvertTextToTokenIds( } if (this_sentence.size() > 1) { - ans.push_back(std::move(this_sentence)); + ans.emplace_back(std::move(this_sentence)); } } diff --git a/sherpa-onnx/csrc/offline-tts-frontend.h b/sherpa-onnx/csrc/offline-tts-frontend.h index 6ea4c5dfa..0216284f1 100644 --- a/sherpa-onnx/csrc/offline-tts-frontend.h +++ b/sherpa-onnx/csrc/offline-tts-frontend.h @@ -15,12 +15,12 @@ namespace sherpa_onnx { struct TokenIDs { TokenIDs() = default; - /*implicit*/ TokenIDs(const std::vector &tokens) // NOLINT - : tokens{tokens} {} + /*implicit*/ TokenIDs(std::vector tokens) // NOLINT + : tokens{std::move(tokens)} {} - TokenIDs(const std::vector &tokens, - const std::vector &tones) - : tokens{tokens}, tones{tones} {} + TokenIDs(std::vector tokens, // NOLINT + std::vector tones) // NOLINT + : tokens{std::move(tokens)}, tones{std::move(tones)} {} std::string ToString() const; diff --git a/sherpa-onnx/csrc/onnx-utils.cc b/sherpa-onnx/csrc/onnx-utils.cc index 1a6bf704b..0f637020a 100644 --- a/sherpa-onnx/csrc/onnx-utils.cc +++ b/sherpa-onnx/csrc/onnx-utils.cc @@ -157,8 +157,8 @@ Ort::Value View(Ort::Value *v) { float ComputeSum(const Ort::Value *v, int32_t n /*= -1*/) { std::vector shape = v->GetTensorTypeAndShapeInfo().GetShape(); - auto size = static_cast(std::accumulate( - shape.begin(), shape.end(), 1, std::multiplies())); + auto size = static_cast( + std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<>())); if (n != -1 && n < size && n > 0) { size = n; } @@ -170,8 +170,8 @@ float ComputeSum(const Ort::Value *v, int32_t n /*= -1*/) { float ComputeMean(const Ort::Value *v, int32_t n /*= -1*/) { std::vector shape = v->GetTensorTypeAndShapeInfo().GetShape(); - auto size = static_cast(std::accumulate( - shape.begin(), shape.end(), 1, std::multiplies())); + auto size = static_cast( + std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<>())); if (n != -1 && n < size && n > 0) { size = n; diff --git a/sherpa-onnx/csrc/piper-phonemize-lexicon.cc b/sherpa-onnx/csrc/piper-phonemize-lexicon.cc index 8ba101cc3..c5f315eae 100644 --- a/sherpa-onnx/csrc/piper-phonemize-lexicon.cc +++ b/sherpa-onnx/csrc/piper-phonemize-lexicon.cc @@ -239,12 +239,12 @@ std::vector PiperPhonemizeLexicon::ConvertTextToTokenIds( if (meta_data_.is_piper || meta_data_.is_icefall) { for (const auto &p : phonemes) { phoneme_ids = PiperPhonemesToIds(token2id_, p); - ans.push_back(std::move(phoneme_ids)); + ans.emplace_back(std::move(phoneme_ids)); } } else if (meta_data_.is_coqui) { for (const auto &p : phonemes) { phoneme_ids = CoquiPhonemesToIds(token2id_, p, meta_data_); - ans.push_back(std::move(phoneme_ids)); + ans.emplace_back(std::move(phoneme_ids)); } } else {