From 5b163ece6dbdad4867902c1d30de644062a2b0ab Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Thu, 6 Jun 2024 22:37:34 -0400 Subject: refactor: less locals --- booki.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/booki.c b/booki.c index a199701..770ea00 100644 --- a/booki.c +++ b/booki.c @@ -22,20 +22,18 @@ char* characters_from_end(char* str, int len_in_bytes, int number_of_chars) { return str; // start at the end of the string, locate all code points - char* newptr = str + len_in_bytes; // will update to last character in do..while unsigned char ch; do { - // update the pointer, get the character - newptr--; + // get the last/previous byte len_in_bytes--; - ch = (unsigned char) *newptr; + ch = (unsigned char) *(str + len_in_bytes); // if we're at the first byte of a unicode point, we've found a whole character if (ch < 0x80 || ch >= 0xC3) number_of_chars--; } while (number_of_chars > 0 && len_in_bytes > 0); - return newptr; + return str + len_in_bytes; } bool comparable(const char* pattern, const char* candidate, int len) { -- cgit v1.2.3