1515#include "object.h"
1616#include "git2/oid.h"
1717
18- GIT__USE_OIDMAP
19-
2018bool git_cache__enabled = true;
2119ssize_t git_cache__max_storage = (256 * 1024 * 1024 );
2220git_atomic_ssize git_cache__current_storage = {0 };
@@ -47,13 +45,13 @@ void git_cache_dump_stats(git_cache *cache)
4745{
4846 git_cached_obj * object ;
4947
50- if (kh_size (cache -> map ) == 0 )
48+ if (git_cache_size (cache ) == 0 )
5149 return ;
5250
53- printf ("Cache %p: %d items cached, %" PRIdZ " bytes\n" ,
54- cache , kh_size (cache -> map ), cache -> used_memory );
51+ printf ("Cache %p: %" PRIuZ " items cached, %"PRIdZ " bytes\n" ,
52+ cache , git_cache_size (cache ), cache -> used_memory );
5553
56- kh_foreach_value (cache -> map , object , {
54+ git_oidmap_foreach_value (cache -> map , object , {
5755 char oid_str [9 ];
5856 printf (" %s%c %s (%" PRIuZ ")\n" ,
5957 git_object_type2string (object -> type ),
@@ -81,14 +79,14 @@ static void clear_cache(git_cache *cache)
8179{
8280 git_cached_obj * evict = NULL ;
8381
84- if (kh_size (cache -> map ) == 0 )
82+ if (git_cache_size (cache ) == 0 )
8583 return ;
8684
87- kh_foreach_value (cache -> map , evict , {
85+ git_oidmap_foreach_value (cache -> map , evict , {
8886 git_cached_obj_decref (evict );
8987 });
9088
91- kh_clear ( oid , cache -> map );
89+ git_oidmap_clear ( cache -> map );
9290 git_atomic_ssize_add (& git_cache__current_storage , - cache -> used_memory );
9391 cache -> used_memory = 0 ;
9492}
@@ -119,22 +117,22 @@ static void cache_evict_entries(git_cache *cache)
119117 ssize_t evicted_memory = 0 ;
120118
121119 /* do not infinite loop if there's not enough entries to evict */
122- if (evict_count > kh_size (cache -> map )) {
120+ if (evict_count > git_cache_size (cache )) {
123121 clear_cache (cache );
124122 return ;
125123 }
126124
127125 while (evict_count > 0 ) {
128- khiter_t pos = seed ++ % kh_end (cache -> map );
126+ khiter_t pos = seed ++ % git_oidmap_end (cache -> map );
129127
130- if (kh_exist (cache -> map , pos )) {
131- git_cached_obj * evict = kh_val (cache -> map , pos );
128+ if (git_oidmap_has_data (cache -> map , pos )) {
129+ git_cached_obj * evict = git_oidmap_value_at (cache -> map , pos );
132130
133131 evict_count -- ;
134132 evicted_memory += evict -> size ;
135133 git_cached_obj_decref (evict );
136134
137- kh_del ( oid , cache -> map , pos );
135+ git_oidmap_delete_at ( cache -> map , pos );
138136 }
139137 }
140138
@@ -156,9 +154,9 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
156154 if (!git_cache__enabled || git_rwlock_rdlock (& cache -> lock ) < 0 )
157155 return NULL ;
158156
159- pos = kh_get ( oid , cache -> map , oid );
160- if (pos != kh_end (cache -> map )) {
161- entry = kh_val (cache -> map , pos );
157+ pos = git_oidmap_lookup_index ( cache -> map , oid );
158+ if (git_oidmap_valid_index (cache -> map , pos )) {
159+ entry = git_oidmap_value_at (cache -> map , pos );
162160
163161 if (flags && entry -> flags != flags ) {
164162 entry = NULL ;
@@ -193,24 +191,22 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
193191 if (git_cache__current_storage .val > git_cache__max_storage )
194192 cache_evict_entries (cache );
195193
196- pos = kh_get ( oid , cache -> map , & entry -> oid );
194+ pos = git_oidmap_lookup_index ( cache -> map , & entry -> oid );
197195
198196 /* not found */
199- if (pos == kh_end (cache -> map )) {
197+ if (! git_oidmap_valid_index (cache -> map , pos )) {
200198 int rval ;
201199
202- pos = kh_put ( oid , cache -> map , & entry -> oid , & rval );
200+ git_oidmap_insert ( cache -> map , & entry -> oid , entry , & rval );
203201 if (rval >= 0 ) {
204- kh_key (cache -> map , pos ) = & entry -> oid ;
205- kh_val (cache -> map , pos ) = entry ;
206202 git_cached_obj_incref (entry );
207203 cache -> used_memory += entry -> size ;
208204 git_atomic_ssize_add (& git_cache__current_storage , (ssize_t )entry -> size );
209205 }
210206 }
211207 /* found */
212208 else {
213- git_cached_obj * stored_entry = kh_val (cache -> map , pos );
209+ git_cached_obj * stored_entry = git_oidmap_value_at (cache -> map , pos );
214210
215211 if (stored_entry -> flags == entry -> flags ) {
216212 git_cached_obj_decref (entry );
@@ -221,8 +217,8 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
221217 git_cached_obj_decref (stored_entry );
222218 git_cached_obj_incref (entry );
223219
224- kh_key (cache -> map , pos ) = & entry -> oid ;
225- kh_val (cache -> map , pos ) = entry ;
220+ git_oidmap_set_key_at (cache -> map , pos , & entry -> oid ) ;
221+ git_oidmap_set_value_at (cache -> map , pos , entry ) ;
226222 } else {
227223 /* NO OP */
228224 }
0 commit comments