Skip to content

Commit 55c8433

Browse files
committed
mwindow: include both the offset and the extra in the same call
This makes it a bit easier to read while letting the caller specify how big the hash size is for this particular call.
1 parent 13502d9 commit 55c8433

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/libgit2/mwindow.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,16 @@ int git_mwindow_free_all(git_mwindow_file *mwf)
186186
}
187187

188188
/*
189-
* Check if a window 'win' contains the address 'offset'
189+
* Check if a window 'win' contains both the address 'offset' and 'extra'.
190+
*
191+
* 'extra' is the size of the hash we're using as we always want to make sure
192+
* that it's contained.
190193
*/
191-
int git_mwindow_contains(git_mwindow *win, off64_t offset)
194+
int git_mwindow_contains(git_mwindow *win, off64_t offset, off64_t extra)
192195
{
193196
off64_t win_off = win->offset;
194197
return win_off <= offset
195-
&& offset <= (off64_t)(win_off + win->window_map.len);
198+
&& (offset + extra) <= (off64_t)(win_off + win->window_map.len);
196199
}
197200

198201
#define GIT_MWINDOW__LRU -1
@@ -406,14 +409,13 @@ unsigned char *git_mwindow_open(
406409
return NULL;
407410
}
408411

409-
if (!w || !(git_mwindow_contains(w, offset) && git_mwindow_contains(w, offset + extra))) {
412+
if (!w || !(git_mwindow_contains(w, offset, extra))) {
410413
if (w) {
411414
w->inuse_cnt--;
412415
}
413416

414417
for (w = mwf->windows; w; w = w->next) {
415-
if (git_mwindow_contains(w, offset) &&
416-
git_mwindow_contains(w, offset + extra))
418+
if (git_mwindow_contains(w, offset, extra))
417419
break;
418420
}
419421

src/libgit2/mwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef struct git_mwindow_ctl {
3838
git_vector windowfiles;
3939
} git_mwindow_ctl;
4040

41-
int git_mwindow_contains(git_mwindow *win, off64_t offset);
41+
int git_mwindow_contains(git_mwindow *win, off64_t offset, off64_t extra);
4242
int git_mwindow_free_all(git_mwindow_file *mwf); /* locks */
4343
unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, off64_t offset, size_t extra, unsigned int *left);
4444
int git_mwindow_file_register(git_mwindow_file *mwf);

0 commit comments

Comments
 (0)