Skip to content

Commit 299f1a8

Browse files
authored
Fix style issues reported by clang-tidy (#1167)
1 parent d32a461 commit 299f1a8

7 files changed

+21
-22
lines changed

sherpa-onnx/csrc/jieba-lexicon.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ class JiebaLexicon::Impl {
102102
this_sentence.push_back(blank);
103103

104104
if (w == "" || w == "" || w == "" || w == "") {
105-
ans.push_back(std::move(this_sentence));
105+
ans.emplace_back(std::move(this_sentence));
106106
this_sentence = {};
107107
}
108108
} // for (const auto &w : words)
109109

110110
if (!this_sentence.empty()) {
111-
ans.push_back(std::move(this_sentence));
111+
ans.emplace_back(std::move(this_sentence));
112112
}
113113

114114
return ans;

sherpa-onnx/csrc/lexicon.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ std::vector<TokenIDs> Lexicon::ConvertTextToTokenIdsChinese(
253253
if (eos != -1) {
254254
this_sentence.push_back(eos);
255255
}
256-
ans.push_back(std::move(this_sentence));
256+
ans.emplace_back(std::move(this_sentence));
257257
this_sentence = {};
258258

259259
if (sil != -1) {
@@ -283,7 +283,7 @@ std::vector<TokenIDs> Lexicon::ConvertTextToTokenIdsChinese(
283283
if (eos != -1) {
284284
this_sentence.push_back(eos);
285285
}
286-
ans.push_back(std::move(this_sentence));
286+
ans.emplace_back(std::move(this_sentence));
287287

288288
return ans;
289289
}
@@ -324,7 +324,7 @@ std::vector<TokenIDs> Lexicon::ConvertTextToTokenIdsNotChinese(
324324

325325
if (w != ",") {
326326
this_sentence.push_back(blank);
327-
ans.push_back(std::move(this_sentence));
327+
ans.emplace_back(std::move(this_sentence));
328328
this_sentence = {};
329329
}
330330

@@ -348,7 +348,7 @@ std::vector<TokenIDs> Lexicon::ConvertTextToTokenIdsNotChinese(
348348
}
349349

350350
if (!this_sentence.empty()) {
351-
ans.push_back(std::move(this_sentence));
351+
ans.emplace_back(std::move(this_sentence));
352352
}
353353

354354
return ans;

sherpa-onnx/csrc/melo-tts-lexicon.cc

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class MeloTtsLexicon::Impl {
9191
std::vector<TokenIDs> ans;
9292
TokenIDs this_sentence;
9393

94-
int32_t blank = token2id_.at("_");
9594
for (const auto &w : words) {
9695
auto ids = ConvertWordToIds(w);
9796
if (ids.tokens.empty()) {

sherpa-onnx/csrc/offline-tts-character-frontend.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ std::vector<TokenIDs> OfflineTtsCharacterFrontend::ConvertTextToTokenIds(
136136
this_sentence.push_back(eos_id);
137137
}
138138

139-
ans.push_back(std::move(this_sentence));
139+
ans.emplace_back(std::move(this_sentence));
140140
this_sentence = {};
141141

142142
// re-initialize this_sentence
@@ -152,7 +152,7 @@ std::vector<TokenIDs> OfflineTtsCharacterFrontend::ConvertTextToTokenIds(
152152
}
153153

154154
if (static_cast<int32_t>(this_sentence.size()) > 1 + use_eos_bos) {
155-
ans.push_back(std::move(this_sentence));
155+
ans.emplace_back(std::move(this_sentence));
156156
}
157157
} else {
158158
// not adding blank
@@ -171,7 +171,7 @@ std::vector<TokenIDs> OfflineTtsCharacterFrontend::ConvertTextToTokenIds(
171171
this_sentence.push_back(eos_id);
172172
}
173173

174-
ans.push_back(std::move(this_sentence));
174+
ans.emplace_back(std::move(this_sentence));
175175
this_sentence = {};
176176

177177
// re-initialize this_sentence
@@ -182,7 +182,7 @@ std::vector<TokenIDs> OfflineTtsCharacterFrontend::ConvertTextToTokenIds(
182182
}
183183

184184
if (this_sentence.size() > 1) {
185-
ans.push_back(std::move(this_sentence));
185+
ans.emplace_back(std::move(this_sentence));
186186
}
187187
}
188188

sherpa-onnx/csrc/offline-tts-frontend.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ namespace sherpa_onnx {
1515
struct TokenIDs {
1616
TokenIDs() = default;
1717

18-
/*implicit*/ TokenIDs(const std::vector<int64_t> &tokens) // NOLINT
19-
: tokens{tokens} {}
18+
/*implicit*/ TokenIDs(std::vector<int64_t> tokens) // NOLINT
19+
: tokens{std::move(tokens)} {}
2020

21-
TokenIDs(const std::vector<int64_t> &tokens,
22-
const std::vector<int64_t> &tones)
23-
: tokens{tokens}, tones{tones} {}
21+
TokenIDs(std::vector<int64_t> tokens, // NOLINT
22+
std::vector<int64_t> tones) // NOLINT
23+
: tokens{std::move(tokens)}, tones{std::move(tones)} {}
2424

2525
std::string ToString() const;
2626

sherpa-onnx/csrc/onnx-utils.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ Ort::Value View(Ort::Value *v) {
157157

158158
float ComputeSum(const Ort::Value *v, int32_t n /*= -1*/) {
159159
std::vector<int64_t> shape = v->GetTensorTypeAndShapeInfo().GetShape();
160-
auto size = static_cast<int32_t>(std::accumulate(
161-
shape.begin(), shape.end(), 1, std::multiplies<int64_t>()));
160+
auto size = static_cast<int32_t>(
161+
std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<>()));
162162
if (n != -1 && n < size && n > 0) {
163163
size = n;
164164
}
@@ -170,8 +170,8 @@ float ComputeSum(const Ort::Value *v, int32_t n /*= -1*/) {
170170

171171
float ComputeMean(const Ort::Value *v, int32_t n /*= -1*/) {
172172
std::vector<int64_t> shape = v->GetTensorTypeAndShapeInfo().GetShape();
173-
auto size = static_cast<int32_t>(std::accumulate(
174-
shape.begin(), shape.end(), 1, std::multiplies<int64_t>()));
173+
auto size = static_cast<int32_t>(
174+
std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<>()));
175175

176176
if (n != -1 && n < size && n > 0) {
177177
size = n;

sherpa-onnx/csrc/piper-phonemize-lexicon.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ std::vector<TokenIDs> PiperPhonemizeLexicon::ConvertTextToTokenIds(
239239
if (meta_data_.is_piper || meta_data_.is_icefall) {
240240
for (const auto &p : phonemes) {
241241
phoneme_ids = PiperPhonemesToIds(token2id_, p);
242-
ans.push_back(std::move(phoneme_ids));
242+
ans.emplace_back(std::move(phoneme_ids));
243243
}
244244
} else if (meta_data_.is_coqui) {
245245
for (const auto &p : phonemes) {
246246
phoneme_ids = CoquiPhonemesToIds(token2id_, p, meta_data_);
247-
ans.push_back(std::move(phoneme_ids));
247+
ans.emplace_back(std::move(phoneme_ids));
248248
}
249249

250250
} else {

0 commit comments

Comments
 (0)