@@ -367,18 +367,17 @@ static int ref_entry_cmp_sslice(const void *key_, const void *ent_)
367
367
}
368
368
369
369
/*
370
- * Return the entry with the given refname from the ref_dir
371
- * (non-recursively), sorting dir if necessary. Return NULL if no
372
- * such entry is found. dir must already be complete.
370
+ * Return the index of the entry with the given refname from the
371
+ * ref_dir (non-recursively), sorting dir if necessary. Return -1 if
372
+ * no such entry is found. dir must already be complete.
373
373
*/
374
- static struct ref_entry * search_ref_dir (struct ref_dir * dir ,
375
- const char * refname , size_t len )
374
+ static int search_ref_dir (struct ref_dir * dir , const char * refname , size_t len )
376
375
{
377
376
struct ref_entry * * r ;
378
377
struct string_slice key ;
379
378
380
379
if (refname == NULL || !dir -> nr )
381
- return NULL ;
380
+ return -1 ;
382
381
383
382
sort_ref_dir (dir );
384
383
key .len = len ;
@@ -387,9 +386,9 @@ static struct ref_entry *search_ref_dir(struct ref_dir *dir,
387
386
ref_entry_cmp_sslice );
388
387
389
388
if (r == NULL )
390
- return NULL ;
389
+ return -1 ;
391
390
392
- return * r ;
391
+ return r - dir -> entries ;
393
392
}
394
393
395
394
/*
@@ -403,8 +402,9 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
403
402
const char * subdirname , size_t len ,
404
403
int mkdir )
405
404
{
406
- struct ref_entry * entry = search_ref_dir (dir , subdirname , len );
407
- if (!entry ) {
405
+ int entry_index = search_ref_dir (dir , subdirname , len );
406
+ struct ref_entry * entry ;
407
+ if (entry_index == -1 ) {
408
408
if (!mkdir )
409
409
return NULL ;
410
410
/*
@@ -415,6 +415,8 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
415
415
*/
416
416
entry = create_dir_entry (dir -> ref_cache , subdirname , len , 0 );
417
417
add_entry_to_dir (dir , entry );
418
+ } else {
419
+ entry = dir -> entries [entry_index ];
418
420
}
419
421
return get_ref_dir (entry );
420
422
}
@@ -453,12 +455,16 @@ static struct ref_dir *find_containing_dir(struct ref_dir *dir,
453
455
*/
454
456
static struct ref_entry * find_ref (struct ref_dir * dir , const char * refname )
455
457
{
458
+ int entry_index ;
456
459
struct ref_entry * entry ;
457
460
dir = find_containing_dir (dir , refname , 0 );
458
461
if (!dir )
459
462
return NULL ;
460
- entry = search_ref_dir (dir , refname , strlen (refname ));
461
- return (entry && !(entry -> flag & REF_DIR )) ? entry : NULL ;
463
+ entry_index = search_ref_dir (dir , refname , strlen (refname ));
464
+ if (entry_index == -1 )
465
+ return NULL ;
466
+ entry = dir -> entries [entry_index ];
467
+ return (entry -> flag & REF_DIR ) ? NULL : entry ;
462
468
}
463
469
464
470
/*
0 commit comments