Use restrict on pointers where it makes sense. (requires C99 support,

which we already assume)
This commit is contained in:
Nils O. Selåsdal
2014-05-25 23:07:08 +02:00
parent fe7c152631
commit b3b1179c5a
12 changed files with 37 additions and 37 deletions
+8 -8
View File
@@ -47,7 +47,7 @@ void uc_dstr_destroy(struct DStr *str);
*
* @return 0 if success, != 0 if allocation fails
*/
int uc_dstr_copy(struct DStr *dest, const struct DStr *src);
int uc_dstr_copy(struct DStr *restrict dest, const struct DStr *restrict src);
/**
* @return the available/unused tail bytes in the string.
@@ -95,7 +95,7 @@ char *uc_dstr_put(struct DStr *str, size_t len);
* @param is_x ctype.h compatible function to use as a filter.
* @return number of chars appended
*/
size_t uc_dstr_put_str_filter(struct DStr *str, const char *s, int (*is_x)(int c));
size_t uc_dstr_put_str_filter(struct DStr *str, const char *restrict s, int (*is_x)(int c));
/* Append a string of the give size.
* (The nul terminator is not appended)
@@ -104,14 +104,14 @@ size_t uc_dstr_put_str_filter(struct DStr *str, const char *s, int (*is_x)(int c
* @param len bytes to append (not including the nul terminator)
* @return 0 on success (!= 0 if an allocation fail)
*/
int uc_dstr_put_str_sz(struct DStr *str, const char *s, size_t len);
int uc_dstr_put_str_sz(struct DStr *str, const char *restrict s, size_t len);
/* Append a string.
* (The nul terminator is not appended)
*
* @return 0 on success (!= 0 if an allocation fail)
*/
int uc_dstr_put_str(struct DStr *str, const char *s);
int uc_dstr_put_str(struct DStr *str, const char *restrict s);
/* Append a single char.
*
@@ -122,7 +122,7 @@ int uc_dstr_put_char(struct DStr *str, char c);
/* Make the DStr take ownership of the given dynamically allocated string.
* Any existing string in the DStr is freed.
*/
void uc_dstr_own(struct DStr *str, char *s);
void uc_dstr_own(struct DStr *str, char *restrict s);
/** Release the managed string.
* The caller is now responsible for managing/free'ing the returned string.
@@ -133,7 +133,7 @@ void uc_dstr_own(struct DStr *str, char *s);
char *uc_dstr_steal(struct DStr *str);
/** Swap the A and B DStr */
void uc_str_swap(struct DStr *a, struct DStr *b);
void uc_str_swap(struct DStr *restrict a, struct DStr *restrict b);
/** Replace all occurences in the DStr
* (This may be used to replace any embedded nul bytes too)
@@ -149,10 +149,10 @@ size_t uc_dstr_replace(struct DStr *str, char f, char r);
void uc_dstr_trim(struct DStr *str);
/** Append formatted string (just as sprintf)*/
int uc_dstr_sprintf(struct DStr *str, const char *fmt, ...) __attribute__((format(printf,2,3)));
int uc_dstr_sprintf(struct DStr *str, const char *restrict fmt, ...) __attribute__((format(printf,2,3)));
/** va_list variant */
int uc_dstr_vsprintf(struct DStr *str, const char *fmt, va_list ap_)__attribute__((format(printf,2,0)));
int uc_dstr_vsprintf(struct DStr *str, const char *restrict fmt, va_list ap_)__attribute__((format(printf,2,0)));
#ifdef __cplusplus
}
+1 -1
View File
@@ -125,7 +125,7 @@ struct MBuf *uc_mbuf_copy_data(struct MBuf *mbuf);
* @param headroom the headroom in the buffer
* @param flags The appropriate UC_MBUF_FLAGS
*/
void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags);
void uc_mbuf_init(struct MBuf *mbuf, uint8_t *restrict buf, uint32_t len, uint32_t headroom, uint32_t flags);
/** Zero out all the data in this mbuf, including the headroom
*
+6 -6
View File
@@ -18,7 +18,7 @@ extern "C" {
* @param out where to store result. Must hold at least len * 2 + 1
* @return returns one past the end of the converted data
*/
char* uc_hex_encode(const uint8_t *in, size_t len, char *out);
char* uc_hex_encode(const uint8_t *restrict in, size_t len, char *restrict out);
/** Decode hex. Will stop at the first non-convertible hex-digit
* spaces(' ','\t,'\r','\n') in input are skipped
@@ -32,11 +32,11 @@ char* uc_hex_encode(const uint8_t *in, size_t len, char *out);
* @param out where to store result. Must hold at least maxlen/2 + 1
* @return returns one past the end of the converted data
*/
uint8_t* uc_hex_decode(const char *in, size_t maxlen,uint8_t *out);
uint8_t* uc_hex_decode(const char *restrict in, size_t maxlen,uint8_t *restrict out);
/** As uc_hex_encode , but inserts the @delim string between each converted
* byte (each 2 hex chars)
*/
char* uc_hex_encode_delim(const uint8_t *in, size_t inlen, char *out, int outlen, const char *delim);
char* uc_hex_encode_delim(const uint8_t *restrict in, size_t inlen, char *restrict out, int outlen, const char *restrict delim);
/**
* Convert the string to lowercase, calls tolower() on each char.
@@ -67,7 +67,7 @@ void uc_str_toupper(char *s);
* if the number of ASCII digits is odd. This would usually be 0x0 or 0xf.
* @return the number of bytes written to bcdout
*/
size_t uc_ascii2bcd(const char *ascii, unsigned char *bcdout, unsigned char filler);
size_t uc_ascii2bcd(const char *restrict ascii, unsigned char *restrict bcdout, unsigned char filler);
/** Convert the BCD digits to ascii.
* The resulting ascii string is 0 terminated.
@@ -77,7 +77,7 @@ size_t uc_ascii2bcd(const char *ascii, unsigned char *bcdout, unsigned char fill
* @param asciiout buffer to place ASCII in, must be UC_ASCII_LEN(bcdlen)+1 big
* @return the number of characters written to bcdout (this will always be UC_ASCII_LEN(bcdlen)
*/
size_t uc_bcd2ascii(const unsigned char *bcd, size_t bcdlen, char *asciiout);
size_t uc_bcd2ascii(const unsigned char *restrict bcd, size_t bcdlen, char *restrict asciiout);
/** uc_sprintb for converting the values into ascii bit representation
* e.g. 0x3 -> "00000011". The result must be able to hold the max number
@@ -111,7 +111,7 @@ char * uc_human_bytesz_bin(uint64_t bytes, char *result, size_t result_len);
* is normally the size of the dst buffer)
* return strlen(src) which may be larger than the no. of bytes copied.
*/
size_t uc_strlcpy(char *dst, const char *src, size_t max);
size_t uc_strlcpy(char *restrict dst, const char *restrict src, size_t max);
#ifdef __cplusplus
}
+3 -3
View File
@@ -52,7 +52,7 @@ int uc_strv_check_expand(struct UCStrv *strv);
* @param str String to append, the string will be copied.
* @return 0 on success, otherwise failure
**/
int uc_strv_append(struct UCStrv *strv, const char *str);
int uc_strv_append(struct UCStrv *strv, const char *restrict str);
/**
* Append a string to the strvec, nocopy variang.
@@ -63,7 +63,7 @@ int uc_strv_append(struct UCStrv *strv, const char *str);
* @param str the string to append
* @return 0 on success, otherwise failure
**/
int uc_strv_append_nocopy(struct UCStrv *strv, char *str);
int uc_strv_append_nocopy(struct UCStrv *strv, char *restrict str);
/**
* Append a NULL pointer to the UCStrv, (cnt is not increased,
@@ -98,7 +98,7 @@ void uc_strv_destroy(struct UCStrv *strv);
* 0 to just append the same pointer in b to a
* @return 0 on success, != 0 if appending/allocation fails
*/
int uc_strv_append_all(struct UCStrv *a, struct UCStrv *b, int copy);
int uc_strv_append_all(struct UCStrv *restrict a, struct UCStrv *restrict b, int copy);
#ifdef __cplusplus
}
+1 -1
View File
@@ -48,6 +48,6 @@ const char *uc_val_2_str_bs(unsigned int val,
* @param array array to search
* @return the string associated with @val or null
*/
const char *uc_str_2_str(const char *val, const struct UCStrStr *array);
const char *uc_str_2_str(const char *restrict val, const struct UCStrStr *array);
#endif