Skip to content

Commit

Permalink
Add sk_ignore_unused_variable to avoid warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
bungeman@google.com committed Feb 4, 2013
1 parent c1aa543 commit 0bfd4f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 4 additions & 7 deletions bench/ChecksumBench.cpp
Expand Up @@ -11,8 +11,7 @@
#include "SkMD5.h"
#include "SkRandom.h"
#include "SkSHA1.h"

template<typename T> inline void sk_ignore_unused(const T&) { }
#include "SkTemplates.h"

enum ChecksumType {
kChecksum_ChecksumType,
Expand Down Expand Up @@ -57,7 +56,7 @@ class ComputeChecksumBench : public SkBenchmark {
case kChecksum_ChecksumType: {
for (int i = 0; i < N; i++) {
volatile uint32_t result = SkChecksum::Compute(fData, sizeof(fData));
sk_ignore_unused(result);
sk_ignore_unused_variable(result);
}
} break;
case kMD5_ChecksumType: {
Expand All @@ -66,7 +65,6 @@ class ComputeChecksumBench : public SkBenchmark {
md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData));
SkMD5::Digest digest;
md5.finish(digest);
sk_ignore_unused(digest);
}
} break;
case kSHA1_ChecksumType: {
Expand All @@ -75,19 +73,18 @@ class ComputeChecksumBench : public SkBenchmark {
sha1.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData));
SkSHA1::Digest digest;
sha1.finish(digest);
sk_ignore_unused(digest);
}
} break;
case kCityHash32: {
for (int i = 0; i < N; i++) {
volatile uint32_t result = SkCityHash::Compute32(reinterpret_cast<char*>(fData), sizeof(fData));
sk_ignore_unused(result);
sk_ignore_unused_variable(result);
}
} break;
case kCityHash64: {
for (int i = 0; i < N; i++) {
volatile uint64_t result = SkCityHash::Compute64(reinterpret_cast<char*>(fData), sizeof(fData));
sk_ignore_unused(result);
sk_ignore_unused_variable(result);
}
} break;
}
Expand Down
6 changes: 6 additions & 0 deletions include/core/SkTemplates.h
Expand Up @@ -19,6 +19,12 @@
resource management.
*/

/**
* Marks a local variable as known to be unused (to avoid warnings).
* Note that this does *not* prevent the local variable from being optimized away.
*/
template<typename T> inline void sk_ignore_unused_variable(const T&) { }

/**
* SkTIsConst<T>::value is true if the type T is const.
* The type T is constrained not to be an array or reference type.
Expand Down

0 comments on commit 0bfd4f1

Please sign in to comment.