diff options
author | Carlos Martín Nieto <carlosmn@github.com> | 2022-04-29 10:32:45 +0200 |
---|---|---|
committer | Carlos Martín Nieto <carlosmn@github.com> | 2022-04-29 10:49:58 +0200 |
commit | 55c843336b04d3d2a79f24f145ad5db1f3537792 (patch) | |
tree | 995a39aadd13aae15d444897a557ca2222d0e41f | |
parent | 13502d9e7f6c51a5f93ea39e14db707d382dc996 (diff) | |
download | libgit2-55c843336b04d3d2a79f24f145ad5db1f3537792.tar.gz |
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.
-rw-r--r-- | src/libgit2/mwindow.c | 14 | ||||
-rw-r--r-- | src/libgit2/mwindow.h | 2 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/libgit2/mwindow.c b/src/libgit2/mwindow.c index d06b7a80e..5c5f9a893 100644 --- a/src/libgit2/mwindow.c +++ b/src/libgit2/mwindow.c @@ -186,13 +186,16 @@ int git_mwindow_free_all(git_mwindow_file *mwf) } /* - * Check if a window 'win' contains the address 'offset' + * Check if a window 'win' contains both the address 'offset' and 'extra'. + * + * 'extra' is the size of the hash we're using as we always want to make sure + * that it's contained. */ -int git_mwindow_contains(git_mwindow *win, off64_t offset) +int git_mwindow_contains(git_mwindow *win, off64_t offset, off64_t extra) { off64_t win_off = win->offset; return win_off <= offset - && offset <= (off64_t)(win_off + win->window_map.len); + && (offset + extra) <= (off64_t)(win_off + win->window_map.len); } #define GIT_MWINDOW__LRU -1 @@ -406,14 +409,13 @@ unsigned char *git_mwindow_open( return NULL; } - if (!w || !(git_mwindow_contains(w, offset) && git_mwindow_contains(w, offset + extra))) { + if (!w || !(git_mwindow_contains(w, offset, extra))) { if (w) { w->inuse_cnt--; } for (w = mwf->windows; w; w = w->next) { - if (git_mwindow_contains(w, offset) && - git_mwindow_contains(w, offset + extra)) + if (git_mwindow_contains(w, offset, extra)) break; } diff --git a/src/libgit2/mwindow.h b/src/libgit2/mwindow.h index e3a03f019..e32ab99d4 100644 --- a/src/libgit2/mwindow.h +++ b/src/libgit2/mwindow.h @@ -38,7 +38,7 @@ typedef struct git_mwindow_ctl { git_vector windowfiles; } git_mwindow_ctl; -int git_mwindow_contains(git_mwindow *win, off64_t offset); +int git_mwindow_contains(git_mwindow *win, off64_t offset, off64_t extra); int git_mwindow_free_all(git_mwindow_file *mwf); /* locks */ unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, off64_t offset, size_t extra, unsigned int *left); int git_mwindow_file_register(git_mwindow_file *mwf); |