diff options
author | Sven Strickroth <email@cs-ware.de> | 2012-10-02 17:16:22 +0200 |
---|---|---|
committer | Sven Strickroth <email@cs-ware.de> | 2012-10-02 17:16:22 +0200 |
commit | 8b3de0b6b8104019def3ddedcf2750539ea7409f (patch) | |
tree | a62b876dddc51e6aff9f4e972f48e83c56c505da /src/fileops.c | |
parent | 19aa8416e59e6c8f01c6b850ce6bb3e2f7457236 (diff) | |
download | libgit2-8b3de0b6b8104019def3ddedcf2750539ea7409f.tar.gz |
Optimized win32_nextpath
Based on a suggestion by Russell Belfer.
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Signed-off-by: Russell Belfer <rb@github.com>
Diffstat (limited to 'src/fileops.c')
-rw-r--r-- | src/fileops.c | 52 |
1 files changed, 10 insertions, 42 deletions
diff --git a/src/fileops.c b/src/fileops.c index cbc7419e0..d99e117bd 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -418,55 +418,23 @@ static int win32_find_file(git_buf *path, const struct win32_path *root, const c git__free(file_utf16); return 0; } - -static wchar_t * win32_nextpath(wchar_t * src, wchar_t * dst, size_t maxlen) +static wchar_t* win32_nextpath(wchar_t *path, wchar_t *buf, size_t buflen) { - wchar_t * orgsrc; - - while (*src == L';') - src++; + wchar_t term, *base = path; - orgsrc = src; + assert(path && buf && buflen); - if (!--maxlen) - goto nullterm; + term = (*path == L'"') ? *path++ : L';'; - while (*src && *src != L';') - { - if (*src != L'"') - { - *dst++ = *src++; - if (!--maxlen) - { - orgsrc = src; - goto nullterm; - } - } - else - { - src++; - while (*src && *src != L'"') - { - *dst++ = *src++; - if (!--maxlen) - { - orgsrc = src; - goto nullterm; - } - } - - if (*src) - src++; - } - } + for (buflen--; *path && *path != term && buflen; buflen--) + *buf++ = *path++; - while (*src == L';') - src++; + *buf = L'\0'; /* reserved a byte via initial subtract */ -nullterm: - *dst = 0; + while (*path == term || *path == L';') + path++; - return (orgsrc != src) ? (wchar_t *)src : NULL; + return (path != base) ? path : NULL; } static int win32_find_system_file_using_path(git_buf *path, const char *filename) |