Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
25f258e7
Commit
25f258e7
authored
Apr 23, 2012
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving power-of-two bit utilities into util.h
parent
da3b391c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
9 deletions
+19
-9
src/cache.c
+2
-9
src/util.h
+17
-0
No files found.
src/cache.c
View file @
25f258e7
...
@@ -9,21 +9,14 @@
...
@@ -9,21 +9,14 @@
#include "repository.h"
#include "repository.h"
#include "commit.h"
#include "commit.h"
#include "thread-utils.h"
#include "thread-utils.h"
#include "util.h"
#include "cache.h"
#include "cache.h"
int
git_cache_init
(
git_cache
*
cache
,
size_t
size
,
git_cached_obj_freeptr
free_ptr
)
int
git_cache_init
(
git_cache
*
cache
,
size_t
size
,
git_cached_obj_freeptr
free_ptr
)
{
{
if
(
size
<
8
)
if
(
size
<
8
)
size
=
8
;
size
=
8
;
size
=
git__size_t_powerof2
(
size
);
/* 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
++
;
cache
->
size_mask
=
size
-
1
;
cache
->
size_mask
=
size
-
1
;
cache
->
lru_count
=
0
;
cache
->
lru_count
=
0
;
...
...
src/util.h
View file @
25f258e7
...
@@ -179,4 +179,21 @@ GIT_INLINE(int) git__ishex(const char *str)
...
@@ -179,4 +179,21 @@ GIT_INLINE(int) git__ishex(const char *str)
return
1
;
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__ */
#endif
/* INCLUDE_util_h__ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment