Skip to content

Commit

Permalink
Specify expected POSIX standard
Browse files Browse the repository at this point in the history
  • Loading branch information
axelf4 committed Apr 14, 2024
1 parent ff9d8c0 commit 864d07c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions hotfuzz-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* See the Lisp source for an explanation of the algorithm.
*/
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
Expand Down Expand Up @@ -62,7 +63,7 @@ static void match_row(struct Str a, struct Str b, int *bonuses, unsigned i, int
for (size_t j = 0; j < m; ++j, s = oldc) {
oldc = c[j];
d[j] = MIN(d[j], oldc + g) + (j == m - 1 ? h : 2 * h);
c[j] = MIN(d[j], a.b[i] == b.b[j] ? s - bonuses[i] : 100000);
c[j] = a.b[i] == b.b[j] ? MIN(d[j], s - bonuses[i]) : d[j];
}
}

Expand Down Expand Up @@ -93,9 +94,9 @@ static int calc_cost(struct Str needle, struct Str haystack, bool ignore_case) {
*/
static bool is_match(char *needle, char *haystack, bool ignore_case) {
while (*needle)
if (ignore_case
? (haystack = strpbrk(haystack, (char[]) { *needle, toupper_utf8(*needle), '\0' }))
: (haystack = strchr(haystack, *needle)))
if (haystack = ignore_case
? strpbrk(haystack, (char[]) { *needle, toupper_utf8(*needle), '\0' })
: strchr(haystack, *needle))
++needle, ++haystack; // Skip past matched character
else
return false;
Expand Down
6 changes: 3 additions & 3 deletions hotfuzz.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Large values will decrease performance."
:type 'integer)

;; Pre-allocated vectors make the cost-only calulation optimization
;; Pre-allocated vectors make the cost-only calculation optimization
;; where symmetricity w.r.t. insertions/deletions means it suffices to
;; allocate min(#needle, #haystack) for C/D inapplicable.
(defconst hotfuzz--max-needle-len 128)
Expand Down Expand Up @@ -101,13 +101,13 @@ and ND/PD respectively may alias."
"Highlight destructively the characters NEEDLE matched in HAYSTACK.
HAYSTACK has to be a match according to `hotfuzz-all-completions'."
(let ((n (length haystack)) (m (length needle))
(c (fillarray hotfuzz--c 10000)) (d (fillarray hotfuzz--d 10000))
(case-fold-search completion-ignore-case))
(unless (or (> n hotfuzz--max-haystack-len) (> m hotfuzz--max-needle-len))
(hotfuzz--calc-bonus haystack)
(cl-loop
with rows initially
(cl-loop for i below n and pc = c then nc and pd = d then nd
(cl-loop for i below n and pc = (fillarray hotfuzz--c 10000) then nc
and pd = (fillarray hotfuzz--d 10000) then nd
and nc = (make-vector m 0) and nd = (make-vector m 0) do
(hotfuzz--match-row haystack needle i nc nd pc pd)
(push (cons nc nd) rows))
Expand Down

0 comments on commit 864d07c

Please sign in to comment.