どちらが速いですか:
if (someValue != otherValue) someValue = otherValue;
また
someValue = otherValue;
それとも、同じコードに最適化されますか?
どちらが速いですか:
if (someValue != otherValue) someValue = otherValue;
また
someValue = otherValue;
それとも、同じコードに最適化されますか?
私が使用しているコードベースでは、ほとんどのオブジェクト セッターには次のようなものがあります。
void SetSomeValue(T otherValue)
{
if(someValue!=otherValue)
{
cout << "Somevalue has changed from " << someValue << " to " << othervalue << endl;
someValue=otherValue;
}
}
これにより、開発以外のデバッグが容易になります。(はい、ログに大量のテキストが記録されますが、ランタイム スイッチでログのオンとオフを切り替えることができます。これは単なる例です)。