Other optimization and warning fixes This fixes a warning left by the earlier optimization and addresses one of the other hotspots identified by GProf.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/src/buffer.c b/src/buffer.c
index 29aaf3f..f28aa21 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -12,9 +12,9 @@
/* Used as default value for git_buf->ptr so that people can always
* assume ptr is non-NULL and zero terminated even for new git_bufs.
*/
-char git_buf_initbuf[1];
+char git_buf__initbuf[1];
-static char git_buf__oom;
+char git_buf__oom[1];
#define ENSURE_SIZE(b, d) \
if ((d) > buf->asize && git_buf_grow(b, (d)) < 0)\
@@ -25,7 +25,7 @@ void git_buf_init(git_buf *buf, size_t initial_size)
{
buf->asize = 0;
buf->size = 0;
- buf->ptr = git_buf_initbuf;
+ buf->ptr = git_buf__initbuf;
if (initial_size)
git_buf_grow(buf, initial_size);
@@ -35,7 +35,7 @@ int git_buf_grow(git_buf *buf, size_t target_size)
{
int error = git_buf_try_grow(buf, target_size);
if (error != 0)
- buf->ptr = &git_buf__oom;
+ buf->ptr = git_buf__oom;
return error;
}
@@ -44,7 +44,7 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
char *new_ptr;
size_t new_size;
- if (buf->ptr == &git_buf__oom)
+ if (buf->ptr == git_buf__oom)
return -1;
if (target_size <= buf->asize)
@@ -85,7 +85,7 @@ void git_buf_free(git_buf *buf)
{
if (!buf) return;
- if (buf->ptr != git_buf_initbuf && buf->ptr != &git_buf__oom)
+ if (buf->ptr != git_buf__initbuf && buf->ptr != git_buf__oom)
git__free(buf->ptr);
git_buf_init(buf, 0);
@@ -98,11 +98,15 @@ void git_buf_clear(git_buf *buf)
buf->ptr[0] = '\0';
}
+/* Moved to inline function:
+
bool git_buf_oom(const git_buf *buf)
{
- return (buf->ptr == &git_buf__oom);
+ return (buf->ptr == git_buf__oom);
}
+*/
+
int git_buf_set(git_buf *buf, const char *data, size_t len)
{
if (len == 0 || data == NULL) {
@@ -164,7 +168,7 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
if (len < 0) {
git__free(buf->ptr);
- buf->ptr = &git_buf__oom;
+ buf->ptr = git_buf__oom;
return -1;
}
@@ -244,7 +248,7 @@ char *git_buf_detach(git_buf *buf)
{
char *data = buf->ptr;
- if (buf->asize == 0 || buf->ptr == &git_buf__oom)
+ if (buf->asize == 0 || buf->ptr == git_buf__oom)
return NULL;
git_buf_init(buf, 0);
@@ -448,11 +452,12 @@ int git_buf_common_prefix(git_buf *buf, const git_strarray *strings)
bool git_buf_is_binary(const git_buf *buf)
{
- int i, printable = 0, nonprintable = 0;
+ size_t i;
+ int printable = 0, nonprintable = 0;
for (i = 0; i < buf->size; i++) {
unsigned char c = buf->ptr[i];
- if (c > 0x1F && c < 0x7f)
+ if (c > 0x1F && c < 0x7F)
printable++;
else if (c == '\0')
return true;
diff --git a/src/buffer.h b/src/buffer.h
index 090b435..50c75f6 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -15,9 +15,10 @@ typedef struct {
size_t asize, size;
} git_buf;
-extern char git_buf_initbuf[];
+extern char git_buf__initbuf[];
+extern char git_buf__oom[];
-#define GIT_BUF_INIT { git_buf_initbuf, 0, 0 }
+#define GIT_BUF_INIT { git_buf__initbuf, 0, 0 }
/**
* Initialize a git_buf structure.
@@ -61,7 +62,10 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize);
*
* @return false if no error, true if allocation error
*/
-bool git_buf_oom(const git_buf *buf);
+GIT_INLINE(bool) git_buf_oom(const git_buf *buf)
+{
+ return (buf->ptr == git_buf__oom);
+}
/*
* Functions below that return int value error codes will return 0 on