Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-03-05 23:47:07 +0400
committerRussell Belfer <rb@github.com>2013-03-07 04:44:53 +0400
commited4f95e5d9f2f59dc5d5a4b76a696b0595b6175d (patch)
treec2411be14f8b357b5f639c5c8d947ac53d8032c9 /src/buffer.h
parent9952f24e6cc71ef5ecd13831f783e308aae97c36 (diff)
Add const to some buffer functions
Diffstat (limited to 'src/buffer.h')
-rw-r--r--src/buffer.h11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/buffer.h b/src/buffer.h
index 6e73895b4..5402f3827 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -119,7 +119,7 @@ void git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf);
#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)
-GIT_INLINE(ssize_t) git_buf_rfind_next(git_buf *buf, char ch)
+GIT_INLINE(ssize_t) git_buf_rfind_next(const git_buf *buf, char ch)
{
ssize_t idx = (ssize_t)buf->size - 1;
while (idx >= 0 && buf->ptr[idx] == ch) idx--;
@@ -127,18 +127,17 @@ GIT_INLINE(ssize_t) git_buf_rfind_next(git_buf *buf, char ch)
return idx;
}
-GIT_INLINE(ssize_t) git_buf_rfind(git_buf *buf, char ch)
+GIT_INLINE(ssize_t) git_buf_rfind(const git_buf *buf, char ch)
{
ssize_t idx = (ssize_t)buf->size - 1;
while (idx >= 0 && buf->ptr[idx] != ch) idx--;
return idx;
}
-GIT_INLINE(ssize_t) git_buf_find(git_buf *buf, char ch)
+GIT_INLINE(ssize_t) git_buf_find(const git_buf *buf, char ch)
{
- size_t idx = 0;
- while (idx < buf->size && buf->ptr[idx] != ch) idx++;
- return (idx == buf->size) ? -1 : (ssize_t)idx;
+ void *found = memchr(buf->ptr, ch, buf->size);
+ return found ? (ssize_t)((const char *)found - buf->ptr) : -1;
}
/* Remove whitespace from the end of the buffer */