inlined some short chunk functions, showed up in the profiler
This commit is contained in:
@@ -42,15 +42,6 @@
|
||||
*/
|
||||
chunk_t chunk_empty = { NULL, 0 };
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
chunk_t chunk_create(u_char *ptr, size_t len)
|
||||
{
|
||||
chunk_t chunk = {ptr, len};
|
||||
return chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
@@ -436,39 +427,6 @@ chunk_t chunk_from_base64(chunk_t base64, char *buf)
|
||||
return chunk_create(buf, outlen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
void chunk_free(chunk_t *chunk)
|
||||
{
|
||||
free(chunk->ptr);
|
||||
chunk->ptr = NULL;
|
||||
chunk->len = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
void chunk_clear(chunk_t *chunk)
|
||||
{
|
||||
memset(chunk->ptr, 0, chunk->len);
|
||||
chunk_free(chunk);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
chunk_t chunk_skip(chunk_t chunk, size_t bytes)
|
||||
{
|
||||
if (chunk.len > bytes)
|
||||
{
|
||||
chunk.ptr += bytes;
|
||||
chunk.len -= bytes;
|
||||
return chunk;
|
||||
}
|
||||
return chunk_empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
@@ -484,15 +442,6 @@ int chunk_compare(chunk_t a, chunk_t b)
|
||||
return memcmp(a.ptr, b.ptr, len);
|
||||
};
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
bool chunk_equals(chunk_t a, chunk_t b)
|
||||
{
|
||||
return a.ptr != NULL && b.ptr != NULL &&
|
||||
a.len == b.len && memeq(a.ptr, b.ptr, a.len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*
|
||||
|
||||
@@ -51,7 +51,11 @@ extern chunk_t chunk_empty;
|
||||
/**
|
||||
* Create a new chunk pointing to "ptr" with length "len"
|
||||
*/
|
||||
chunk_t chunk_create(u_char *ptr, size_t len);
|
||||
static inline chunk_t chunk_create(u_char *ptr, size_t len)
|
||||
{
|
||||
chunk_t chunk = {ptr, len};
|
||||
return chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a clone of a chunk pointing to "ptr"
|
||||
@@ -136,12 +140,20 @@ chunk_t chunk_from_base64(chunk_t base64, char *buf);
|
||||
/**
|
||||
* Free contents of a chunk
|
||||
*/
|
||||
void chunk_free(chunk_t *chunk);
|
||||
static inline void chunk_free(chunk_t *chunk)
|
||||
{
|
||||
free(chunk->ptr);
|
||||
*chunk = chunk_empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite the contents of a chunk and free it
|
||||
*/
|
||||
void chunk_clear(chunk_t *chunk);
|
||||
static inline void chunk_clear(chunk_t *chunk)
|
||||
{
|
||||
memset(chunk->ptr, 0, chunk->len);
|
||||
chunk_free(chunk);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a chunk to point to buffer inspectable by sizeof()
|
||||
@@ -186,7 +198,16 @@ void chunk_clear(chunk_t *chunk);
|
||||
/**
|
||||
* Skip n bytes in chunk (forward pointer, shorten length)
|
||||
*/
|
||||
chunk_t chunk_skip(chunk_t chunk, size_t bytes);
|
||||
static inline chunk_t chunk_skip(chunk_t chunk, size_t bytes)
|
||||
{
|
||||
if (chunk.len > bytes)
|
||||
{
|
||||
chunk.ptr += bytes;
|
||||
chunk.len -= bytes;
|
||||
return chunk;
|
||||
}
|
||||
return chunk_empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two chunks, returns zero if a equals b
|
||||
@@ -198,7 +219,11 @@ int chunk_compare(chunk_t a, chunk_t b);
|
||||
* Compare two chunks for equality,
|
||||
* NULL chunks are never equal.
|
||||
*/
|
||||
bool chunk_equals(chunk_t a, chunk_t b);
|
||||
static inline bool chunk_equals(chunk_t a, chunk_t b)
|
||||
{
|
||||
return a.ptr != NULL && b.ptr != NULL &&
|
||||
a.len == b.len && memeq(a.ptr, b.ptr, a.len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a 32 bit hash of the given chunk.
|
||||
|
||||
Reference in New Issue
Block a user