Skip to content

Commit d333dbe

Browse files
authored
Merge pull request libgit2#6288 from libgit2/cmn/mwindow-simplifications
A couple of simplications around mwindow
2 parents 660e6bd + 0f59444 commit d333dbe

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/libgit2/mwindow.c

Lines changed: 9 additions & 9 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
@@ -237,9 +240,7 @@ static bool git_mwindow_scan_recently_used(
237240
* store it in the output parameter. If lru_window is NULL,
238241
* it's the first loop, so store it as well.
239242
*/
240-
if (!lru_window ||
241-
(comparison_sign == GIT_MWINDOW__LRU && lru_window->last_used > w->last_used) ||
242-
(comparison_sign == GIT_MWINDOW__MRU && lru_window->last_used < w->last_used)) {
243+
if (!lru_window || (comparison_sign * w->last_used) > lru_window->last_used) {
243244
lru_window = w;
244245
lru_last = w_last;
245246
found = true;
@@ -406,14 +407,13 @@ unsigned char *git_mwindow_open(
406407
return NULL;
407408
}
408409

409-
if (!w || !(git_mwindow_contains(w, offset) && git_mwindow_contains(w, offset + extra))) {
410+
if (!w || !(git_mwindow_contains(w, offset, extra))) {
410411
if (w) {
411412
w->inuse_cnt--;
412413
}
413414

414415
for (w = mwf->windows; w; w = w->next) {
415-
if (git_mwindow_contains(w, offset) &&
416-
git_mwindow_contains(w, offset + extra))
416+
if (git_mwindow_contains(w, offset, extra))
417417
break;
418418
}
419419

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)