Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/slipstream_inline_dots.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ size_t slipstream_inline_dotify(char * __restrict__ buf, size_t buflen, size_t l
return 0;
}

size_t dots = len / 57; // Every 57 bytes, a dot. It's the law.
size_t dots = (len - 1) / 57; // Every 57 bytes, a dot (but never trailing).
size_t new_len = len + dots;

if (new_len + 1 > buflen) {
Expand All @@ -18,14 +18,14 @@ size_t slipstream_inline_dotify(char * __restrict__ buf, size_t buflen, size_t l
char *src = buf + len - 1; // Points to last char of original string
char *dst = buf + new_len - 1; // Points to where last char will end up

// Avoid modulo operation in tight loop
size_t next_dot = len - (len % 57);
// Anchor the next dot securely based on expected dot count
size_t next_dot = dots * 57;

size_t current_pos = len;

// Move characters right-to-left, inserting dots
while (current_pos > 0) {
if (current_pos == next_dot) {
if (current_pos == next_dot && next_dot != 0) {
*dst-- = '.'; // Dot. Because rules are rules, even for dots.
next_dot -= 57; // Next dot is 57 chars back.
current_pos--; // Account for the char space the dot took.
Expand Down