Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(812)

Unified Diff: third_party/WebKit/Source/platform/audio/AudioUtilities.cpp

Issue 2582323003: Test for power of two safely (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/audio/AudioUtilities.cpp
diff --git a/third_party/WebKit/Source/platform/audio/AudioUtilities.cpp b/third_party/WebKit/Source/platform/audio/AudioUtilities.cpp
index abb0e882cdb725acacac89b3b49e4363aa04f17d..b87ba22346fd502453531dda0189b8df1dae8515 100644
--- a/third_party/WebKit/Source/platform/audio/AudioUtilities.cpp
+++ b/third_party/WebKit/Source/platform/audio/AudioUtilities.cpp
@@ -73,6 +73,14 @@ float maxAudioBufferSampleRate() {
// should too.
return 384000;
}
+
+bool isPowerOfTwo(size_t x) {
+ // From Hacker's Delight. x & (x - 1) turns off (zeroes) the
+ // rightmost 1-bit in the word x. If x is a power of two, then the
+ // result is, of course, 0.
+ return x > 0 && ((x & (x - 1)) == 0);
+}
+
} // namespace AudioUtilities
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698