Skip to content

Commit

Permalink
fast_tolower: a little tidying (why not?)
Browse files Browse the repository at this point in the history
(cherry picked from commit 14b902e50da1df956706f702308b0bb2e817eba5)
  • Loading branch information
andrew-canaday committed Jun 2, 2024
1 parent 8169f35 commit 4c65573
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/ymo_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
#endif /* YMO_UTIL_TRACE */


/** Some of the usual pointer alignment hacks: */
#define STRIDE_ALIGN (SIZEOF_SIZE_T - 1)
#define STRIDE_FLOOR(p) (((uintptr_t)p) & ~STRIDE_ALIGN)
#define STRIDE_CEIL(p) ((((uintptr_t)p) + STRIDE_ALIGN) & ~STRIDE_ALIGN)

/*---------------------------------------------------------------*
* String case conversion macros:
*---------------------------------------------------------------*/
Expand Down Expand Up @@ -138,8 +143,7 @@ void ymo_ntolower(char* dst, const char* src, size_t len)
size_t no_iter = len / SIZEOF_SIZE_T;

/* Number of single byte chunks to arrive at proper alignment: */
size_t align = ((SIZEOF_SIZE_T) - \
((stride_t)(src) % SIZEOF_SIZE_T)) % SIZEOF_SIZE_T;
size_t align = STRIDE_CEIL(src) - ((uintptr_t)src);

/* Number of single byte chunks after main no_iter is done: */
size_t remain = (len % SIZEOF_SIZE_T) - align;
Expand Down Expand Up @@ -224,8 +228,7 @@ void ymo_ntoupper(char* dst, const char* src, size_t len)
size_t no_iter = len / SIZEOF_SIZE_T;

/* Number of single byte chunks to arrive at proper alignment: */
size_t align = ((SIZEOF_SIZE_T) - \
((stride_t)(src) % SIZEOF_SIZE_T)) % SIZEOF_SIZE_T;
size_t align = STRIDE_CEIL(src) - ((uintptr_t)src);

/* Number of single byte chunks after main no_iter is done: */
size_t remain = (len % SIZEOF_SIZE_T) - align;
Expand Down

0 comments on commit 4c65573

Please sign in to comment.