Browse Source

[core] uint_fast32_t tweaks

use uint_fast32_t in a few more places, where it yields better asm
master
Glenn Strauss 3 months ago
parent
commit
57c0859fd7
  1. 8
      src/array.c
  2. 7
      src/buffer.c

8
src/array.c

@ -234,9 +234,9 @@ static int32_t array_get_index_ext(const array * const a, const int ext, const c
/* invariant: [lower-1] < probe < [upper]
* invariant: 0 <= lower <= upper <= a->used
*/
uint32_t lower = 0, upper = a->used;
uint_fast32_t lower = 0, upper = a->used;
while (lower != upper) {
const uint32_t probe = (lower + upper) / 2;
const uint_fast32_t probe = (lower + upper) / 2;
const int x = ((data_string *)a->sorted[probe])->ext;
/* (compare strings only if ext is 0 for both)*/
const int e = (ext|x)
@ -268,9 +268,9 @@ static int32_t array_get_index(const array * const a, const char * const k, cons
/* invariant: [lower-1] < probe < [upper]
* invariant: 0 <= lower <= upper <= a->used
*/
uint32_t lower = 0, upper = a->used;
uint_fast32_t lower = 0, upper = a->used;
while (lower != upper) {
uint32_t probe = (lower + upper) / 2;
uint_fast32_t probe = (lower + upper) / 2;
const buffer * const b = &a->sorted[probe]->key;
/* key is non-empty (0==b->used), though possibly blank (1==b->used),
* if inserted into key-value array */

7
src/buffer.c

@ -755,6 +755,7 @@ void buffer_urldecode_path(buffer * const b) {
int buffer_is_valid_UTF8(const buffer *b) {
/* https://www.w3.org/International/questions/qa-forms-utf-8 */
/*assert(b->used);*//*(b->ptr must exist and be '\0'-terminated)*/
const unsigned char *c = (unsigned char *)b->ptr;
while (*c) {
@ -897,7 +898,8 @@ void buffer_path_simplify(buffer *b)
void buffer_to_lower(buffer * const b) {
unsigned char * const restrict s = (unsigned char *)b->ptr;
for (uint32_t i = 0; i < b->used; ++i) {
const uint_fast32_t used = b->used;
for (uint_fast32_t i = 0; i < used; ++i) {
if (light_isupper(s[i])) s[i] |= 0x20;
}
}
@ -905,7 +907,8 @@ void buffer_to_lower(buffer * const b) {
void buffer_to_upper(buffer * const b) {
unsigned char * const restrict s = (unsigned char *)b->ptr;
for (uint32_t i = 0; i < b->used; ++i) {
const uint_fast32_t used = b->used;
for (uint_fast32_t i = 0; i < used; ++i) {
if (light_islower(s[i])) s[i] &= 0xdf;
}
}

Loading…
Cancel
Save