mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-19 22:44:42 +00:00
Moving power-of-two bit utilities into util.h
This commit is contained in:
parent
da3b391c32
commit
25f258e735
11
src/cache.c
11
src/cache.c
@ -9,21 +9,14 @@
|
||||
#include "repository.h"
|
||||
#include "commit.h"
|
||||
#include "thread-utils.h"
|
||||
#include "util.h"
|
||||
#include "cache.h"
|
||||
|
||||
int git_cache_init(git_cache *cache, size_t size, git_cached_obj_freeptr free_ptr)
|
||||
{
|
||||
if (size < 8)
|
||||
size = 8;
|
||||
|
||||
/* round up size to closest power of 2 */
|
||||
size--;
|
||||
size |= size >> 1;
|
||||
size |= size >> 2;
|
||||
size |= size >> 4;
|
||||
size |= size >> 8;
|
||||
size |= size >> 16;
|
||||
size++;
|
||||
size = git__size_t_powerof2(size);
|
||||
|
||||
cache->size_mask = size - 1;
|
||||
cache->lru_count = 0;
|
||||
|
17
src/util.h
17
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__ */
|
||||
|
Loading…
Reference in New Issue
Block a user