]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
whisper : use emplace_back in place of push_back (#319)
authorAndy Maloney <redacted>
Fri, 23 Dec 2022 09:07:19 +0000 (04:07 -0500)
committerGitHub <redacted>
Fri, 23 Dec 2022 09:07:19 +0000 (11:07 +0200)
This avoids potential construction of temporaries.

whisper.cpp

index 3885977d3127c7bd98aab71e5419ec3b1daf164c..f43bb4a47498b06696682fc13d4340ecfdc4db07 100644 (file)
@@ -1863,7 +1863,7 @@ static whisper_token_data whisper_sample_best(
     probs_id.reserve(n_logits);
 
     for (int i = 0; i < n_logits; i++) {
-        probs_id.push_back(std::make_pair(probs[i], i));
+        probs_id.emplace_back(probs[i], i);
     }
 
     {
@@ -2434,7 +2434,7 @@ int whisper_lang_auto_detect(
     std::vector<std::pair<float, int>> probs_id;
     for (const auto & kv : g_lang) {
         const auto token_lang = whisper_token_lang(ctx, kv.second.first);
-        probs_id.push_back({ ctx->probs[token_lang], kv.second.first });
+        probs_id.emplace_back( ctx->probs[token_lang], kv.second.first );
     }
 
     // sort descending