Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
feat: use bit algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Antares0982 committed May 10, 2024
1 parent 5da4aee commit 51d1fa4
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,17 @@ bool count_skipped(const char *buf, size_t max_len, size_t *skipped, size_t *len
}
} else {
skip_next = 0;
for (int j = 0; j < 32; j++) {
if ((escape_result >> j) & 0b1) {
*skipped += 1;
j++;
if (j > 31) {
skip_next = 1;
}
int last = 0;
uint32_t x = escape_result;
while (x) {
unsigned int y = x - 1;
if ((x >> 1) & last) {
x = x & y; // skipped
} else {
last = x ^ y;
x = x & y;
skipped += 1;
if (y == 0x7fffffff) skip_next = 1;
}
}
}
Expand Down

0 comments on commit 51d1fa4

Please sign in to comment.