メインコンテンツ

パフォーマンスの欠陥

C/C++ コードのパフォーマンスに影響する欠陥

この欠陥は、C/C++ コードのパフォーマンスのボトルネックにつながりかねない問題を検出します。検出される問題には次のものがあります。

  • 移動操作の代わりに誤ってコピーを引き起こす問題

  • 非効率または不必要な一時変数の作成

  • より効率の良い代替手段がある可能性がある関数の使用

Polyspace 結果

すべて展開する

移動操作によってスローされる可能性があります移動操作をスローすると、対応するコピー操作が STL コンテナーで使用される場合がある
const のパラメーター値によって不要なデータ コピーが生じることがありますconst パラメーター値によって移動操作が禁止され、その結果より高いパフォーマンスを必要とするコピー操作が発生することがある
const の戻り値によって不要なデータ コピーが生じることがありますconst の戻り値によって移動操作が禁止され、より高いパフォーマンスが必要なコピー操作が行われる場合がある
const rvalue 参照パラメーターにより、不要なデータ コピーが発生する可能性がありますrvalue 参照の const の特性により、意図された移動操作が妨げられる (R2021a 以降)
Const std::move の入力により、オブジェクト コピーの計算量が増える場合がありますConst std::move 入力は移動できないため、より計算量の多いコピー操作が行われる
空のデストラクターによって不要なデータ コピーが生じることがありますユーザーが宣言した空のデストラクターによって、移動コンストラクターと移動代入演算子の自動生成が回避される
計算量の多い const オブジェクトの戻り値The return statement of a function copies an objects instead of moving it because the returned object is declared as a const (R2022a 以降)
移動操作にコピーが使用されていますNon-const rvalue reference parameter of a function or operator is copied instead of moved (R2021b 以降)
移動不可のタイプで std::move が呼び出されました移動コンストラクターまたは移動代入演算子のないクラス型で std::move が使用される
計算量の多い変数の最後の使用An expensive-to-copy local variable is copied in its final use instead of being moved (R2025a 以降)
範囲ベースの for ループの反復における計算量の多いコピー範囲ベースの for ループのループ変数が参照されるのではなく範囲要素からコピーされるため、非効率なコードになる
計算量の多いローカル変数のコピーですローカル変数が const 参照からのコピーで作成された後、変更されない (R2021a 以降)
計算量の多いメンバー初期化You assign values to class members in the constructor body instead of constructing members using a member initializer list (R2023b 以降)
計算量の多い値渡しパラメーターのコピーの計算量が多くなる場合がある
計算量の多い値返し関数が参照やポインターではなく値で大きな出力を返す
計算量の多い std::any_cast の使用An object is cast by-value using std::any_cast when casting by-reference is more efficient (R2023b 以降)
定数文字列からの、計算量の多い std::string または std::regex の構成A constant std::string or std::regex object is constructed from constant data, resulting in inefficient code
constexpr 指定子が見つかりませんconstexpr 指定子をコンパイル時の評価用の変数または関数に使用できる
再割り当て前の不要な構成Instead of directly constructing objects with value, you construct objects and then immediately assign values to objects (R2023a 以降)
計算量の多い未使用オブジェクトExpensive local object is constructed but not used (R2024a 以降)
std::function の計算量の多い型定義Definition of std::function type uses pass-by-value semantics for arguments that are expensive to copy (R2024a 以降)
計算量の多い dynamic_castExpensive dynamic_cast is used instead of more efficient static_cast or const_cast (R2021b 以降)
計算量の多い標準アルゴリズムを使用していますが、より効率的な方法がありますFunctions from the algorithm library are misused with inappropriate inputs, resulting in inefficient code (R2021b 以降)
単純な追加の代わりに、計算量の多い std::string の非メンバー演算子 +() が使用されています追加 (または +=) メソッドがより効率的であるのに、非メンバー関数 std::string operator+() が呼び出される
より効率的なオーバーロードの代わりに、計算量の多い std::string のメソッドを使用一重引用符で囲んだ文字の代わりに、長さが既知の文字列リテラルで std::string メソッドが呼び出される (R2021a 以降)
空の文字列リテラルに対して計算量の多い std::string を使用空の文字列リテラルに対して std::string を使用する代わりに、より計算量の少ないメンバー関数 std::basic_string の呼び出しができる (R2021a 以降)
C 標準ライブラリから計算量の多い文字列関数を使用String functions from the C standard library are used inefficiently (R2022a 以降)
std::string の短縮に計算量の多い substr() を使用The method std::string::substr() is called to shorten an std::string object (R2022a 以降)
sprintf の使用が非効率的ですThe function sprintf, snprintf, or swprintf copies strings instead of the more efficient strcpy, strncopy, or wcsncpy (R2021b 以降)
string 長の計算が非効率的ですstd::basic_string::length() を使用する代わりに std::basic_string::c_str() からの戻り値に対して文字列長関数を使用することによって文字列長が計算される
std::endl によって不要なフラッシュが生じることがありますstd::endl がより効率的な \n の代わりに使用される
より効率的な make_shared ではなく new または make_unique を使用new または make_unique を使用して shared_ptr を初期化またはリセットすると、追加のメモリ割り当てが発生する (R2021a 以降)
std::string::c_str() または同等の string メソッドの不要な使用Instead of a std::string object, a string operation uses the C-string obtained from std::string functions including std::string::c_str, std::string::data(), std::string::at(), or std::string::operator[], resulting in inefficient code
計算量の多いコンテナーのカウント方法を使用The function member count() of a container is used for checking if a key is present, leading to inefficient code (R2021b 以降)
計算量の多いコンテナーの挿入メソッドを使用One of the insertion methods of a container is used to insert a temporary object (R2022a 以降)
計算量の多い、コンテナーの size メソッドの使用A container's size() method is used for checking emptiness instead of its empty() method, which is more efficient (R2022b 以降)
計算量の多いマップの大かっこ演算子を使用して、値を挿入または代入The bracket operator of std::map or std::unordered_map is used for inserting or assigning a value in the container instead of the insert_or_assign() method, which is more efficient (R2022b 以降)
コンテナーの予約メソッドの呼び出しがありませんA fixed number of items are added to a container without calling the reserve() method of the container beforehand, resulting in inefficient code (R2022b 以降)
セットの代わりに計算量の多いマップを使用The key for a map is member of the object being inserted, resulting in redundant map key (R2024b 以降)
計算量の多い論理演算ですオペランドの順序により、論理演算が両方のオペランドを評価しなければならないため非効率なコードになる (R2021a 以降)
不要な std::move を原因とする計算量の多い戻り値An unnecessary call to std::move in the return statement hinders return value optimization, resulting in inefficient code (R2022b 以降)
ループ内の計算量の多い代入Fixed sized memory is allocated or deallocated in a loop (R2022a 以降)
計算量の多い後置インクリメント演算Object is post-incremented when pre-incrementing is faster (R2021b 以降)
非効率的な for ループの使用Range-based for loop can perform equivalent iteration more efficiently (R2022a 以降)
不必要なパディングstruct のメンバーを再配置してアライメント要件を満たすことでメモリを節約できる場合に、この要件を満たすためのメンバーがパディングされる (R2021b 以降)
特殊なメンバー関数の不要な実装Implementing special member functions hinders code optimization when implicit versions are equivalent (R2023a 以降)
パラメーターへの不要な参照Parameter is passed to function as const reference when passing by value is more efficient (R2024a 以降)

トピック

  • Bug Finder 欠陥グループ

    Bug Finder の欠陥チェッカーは、データ フロー、同時実行、数値などのグループに分類されています。