summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-04-23 09:21:15 -0700
committerRussell Belfer <rb@github.com>2012-04-25 11:14:34 -0700
commit25f258e735f707075dc1b5cdd804540fe1e43f37 (patch)
tree7c319941fb202ee1fba63c781193300e514febb7 /src/util.h
parentda3b391c32b973d5c073951b6848eedd40434e5e (diff)
downloadlibgit2-25f258e735f707075dc1b5cdd804540fe1e43f37.tar.gz
Moving power-of-two bit utilities into util.h
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index afa3f7205..1fee9a70c 100644
--- a/src/util.h
+++ b/src/util.h
@@ -179,4 +179,21 @@ GIT_INLINE(int) git__ishex(const char *str)
return 1;
}
+GIT_INLINE(size_t) git__size_t_bitmask(size_t v)
+{
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+
+ return v;
+}
+
+GIT_INLINE(size_t) git__size_t_powerof2(size_t v)
+{
+ return git__size_t_bitmask(v) + 1;
+}
+
#endif /* INCLUDE_util_h__ */