use __restrict for string functions args so the compiler can assume they dont overlap.
also avoid comparing int/size_t in for loops.
This commit is contained in:
@@ -74,7 +74,7 @@ __attribute__((nonnull))
|
||||
* \param str2 second string for append
|
||||
* \retval Returns dst
|
||||
*/
|
||||
char *BLI_strdupcat(const char *str1, const char *str2)
|
||||
char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((warn_unused_result))
|
||||
__attribute__((nonnull))
|
||||
@@ -91,7 +91,7 @@ __attribute__((nonnull))
|
||||
* the size of dst)
|
||||
* \retval Returns dst
|
||||
*/
|
||||
char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy)
|
||||
char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
@@ -107,7 +107,7 @@ __attribute__((nonnull))
|
||||
* Assume that the strings returned must be freed afterwards, and that the inputs will contain
|
||||
* data we want...
|
||||
*/
|
||||
char *BLI_str_quoted_substrN(const char *str, const char *prefix)
|
||||
char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((warn_unused_result))
|
||||
__attribute__((nonnull))
|
||||
@@ -124,7 +124,7 @@ __attribute__((nonnull))
|
||||
* \param newText The text in the string to find and replace
|
||||
* \retval Returns the duplicated string
|
||||
*/
|
||||
char *BLI_replacestr(char *str, const char *oldText, const char *newText)
|
||||
char *BLI_replacestr(char *__restrict str, const char *__restrict oldText, const char *__restrict newText)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((warn_unused_result))
|
||||
__attribute__((nonnull))
|
||||
@@ -134,7 +134,7 @@ __attribute__((nonnull))
|
||||
/*
|
||||
* Replacement for snprintf
|
||||
*/
|
||||
size_t BLI_snprintf(char *buffer, size_t len, const char *format, ...)
|
||||
size_t BLI_snprintf(char *__restrict buffer, size_t len, const char *__restrict format, ...)
|
||||
#ifdef __GNUC__
|
||||
__attribute__ ((format(printf, 3, 4)))
|
||||
__attribute__((nonnull))
|
||||
@@ -144,7 +144,7 @@ __attribute__((nonnull))
|
||||
/*
|
||||
* Replacement for vsnprintf
|
||||
*/
|
||||
size_t BLI_vsnprintf(char *buffer, size_t count, const char *format, va_list arg)
|
||||
size_t BLI_vsnprintf(char *__restrict buffer, size_t count, const char *__restrict format, va_list arg)
|
||||
#ifdef __GNUC__
|
||||
__attribute__ ((format(printf, 3, 0)))
|
||||
#endif
|
||||
@@ -154,7 +154,7 @@ __attribute__ ((format(printf, 3, 0)))
|
||||
* Print formatted string into a newly mallocN'd string
|
||||
* and return it.
|
||||
*/
|
||||
char *BLI_sprintfN(const char *format, ...)
|
||||
char *BLI_sprintfN(const char *__restrict format, ...)
|
||||
#ifdef __GNUC__
|
||||
__attribute__ ((format(printf, 1, 2)))
|
||||
__attribute__((warn_unused_result))
|
||||
@@ -162,7 +162,7 @@ __attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
size_t BLI_strescape(char *dst, const char *src, const size_t maxlen)
|
||||
size_t BLI_strescape(char *__restrict dst, const char *__restrict src, const size_t maxlen)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
@@ -216,12 +216,12 @@ __attribute__((nonnull))
|
||||
#endif
|
||||
; /* time var is global */
|
||||
|
||||
void BLI_ascii_strtolower(char *str, int len)
|
||||
void BLI_ascii_strtolower(char *str, const size_t len)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
void BLI_ascii_strtoupper(char *str, int len)
|
||||
void BLI_ascii_strtoupper(char *str, const size_t len)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
|
||||
@@ -31,16 +31,16 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *BLI_strncpy_utf8(char *dst, const char *src, size_t maxncpy);
|
||||
char *BLI_strncat_utf8(char *dst, const char *src, size_t maxncpy);
|
||||
char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy);
|
||||
char *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy);
|
||||
int BLI_utf8_invalid_byte(const char *str, int length);
|
||||
int BLI_utf8_invalid_strip(char *str, int length);
|
||||
|
||||
int BLI_str_utf8_size(const char *p); /* warning, can return -1 on bad chars */
|
||||
/* copied from glib */
|
||||
unsigned int BLI_str_utf8_as_unicode(const char *p);
|
||||
unsigned int BLI_str_utf8_as_unicode_and_size(const char *p, size_t *index);
|
||||
unsigned int BLI_str_utf8_as_unicode_step(const char *p, size_t *index);
|
||||
unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index);
|
||||
unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index);
|
||||
size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf);
|
||||
|
||||
char *BLI_str_find_prev_char_utf8(const char *str, const char *p);
|
||||
@@ -50,8 +50,8 @@ char *BLI_str_prev_char_utf8(const char *p);
|
||||
/* wchar_t functions, copied from blenders own font.c originally */
|
||||
size_t BLI_wstrlen_utf8(const wchar_t *src);
|
||||
size_t BLI_strlen_utf8(const char *strc);
|
||||
size_t BLI_strncpy_wchar_as_utf8(char *dst, const wchar_t *src, const size_t maxcpy);
|
||||
size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst, const char *src, const size_t maxcpy);
|
||||
size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxcpy);
|
||||
size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, const size_t maxcpy);
|
||||
|
||||
#define BLI_UTF8_MAX 6
|
||||
#define BLI_UTF8_ERR ((unsigned int)-1)
|
||||
|
||||
@@ -296,11 +296,12 @@ char *BLI_strcasestr(const char *s, const char *find)
|
||||
|
||||
int BLI_strcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
int i;
|
||||
register int i;
|
||||
register char c1, c2;
|
||||
|
||||
for (i = 0;; i++) {
|
||||
char c1 = tolower(s1[i]);
|
||||
char c2 = tolower(s2[i]);
|
||||
c1 = tolower(s1[i]);
|
||||
c2 = tolower(s2[i]);
|
||||
|
||||
if (c1 < c2) {
|
||||
return -1;
|
||||
@@ -318,11 +319,12 @@ int BLI_strcasecmp(const char *s1, const char *s2)
|
||||
|
||||
int BLI_strncasecmp(const char *s1, const char *s2, size_t len)
|
||||
{
|
||||
int i;
|
||||
register size_t i;
|
||||
register char c1, c2;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
char c1 = tolower(s1[i]);
|
||||
char c2 = tolower(s2[i]);
|
||||
c1 = tolower(s1[i]);
|
||||
c2 = tolower(s2[i]);
|
||||
|
||||
if (c1 < c2) {
|
||||
return -1;
|
||||
@@ -341,15 +343,16 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len)
|
||||
/* natural string compare, keeping numbers in order */
|
||||
int BLI_natstrcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int d1 = 0, d2 = 0;
|
||||
register int d1 = 0, d2 = 0;
|
||||
register char c1, c2;
|
||||
|
||||
/* if both chars are numeric, to a strtol().
|
||||
* then increase string deltas as long they are
|
||||
* numeric, else do a tolower and char compare */
|
||||
|
||||
while (1) {
|
||||
char c1 = tolower(s1[d1]);
|
||||
char c2 = tolower(s2[d2]);
|
||||
c1 = tolower(s1[d1]);
|
||||
c2 = tolower(s2[d2]);
|
||||
|
||||
if (isdigit(c1) && isdigit(c2) ) {
|
||||
int val1, val2;
|
||||
@@ -419,18 +422,18 @@ size_t BLI_strnlen(const char *str, size_t maxlen)
|
||||
return end ? (size_t) (end - str) : maxlen;
|
||||
}
|
||||
|
||||
void BLI_ascii_strtolower(char *str, int len)
|
||||
void BLI_ascii_strtolower(char *str, const size_t len)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (str[i] >= 'A' && str[i] <= 'Z')
|
||||
str[i] += 'a' - 'A';
|
||||
}
|
||||
|
||||
void BLI_ascii_strtoupper(char *str, int len)
|
||||
void BLI_ascii_strtoupper(char *str, const size_t len)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (str[i] >= 'a' && str[i] <= 'z')
|
||||
|
||||
Reference in New Issue
Block a user