Skip to content

Commit

Permalink
Merge pull request #485 from nloewen/master
Browse files Browse the repository at this point in the history
Fix regex sort
Thanks @nloewen
  • Loading branch information
SeeSpotRun authored Apr 6, 2021
2 parents 094fbd5 + 367c48e commit 427791c
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions lib/preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,36 +356,28 @@ char *rm_pp_compile_patterns(RmSession *session, const char *sortcrit, GError **
static int rm_pp_cmp_by_regex(GRegex *regex, int idx, RmPatternBitmask *mask_a,
const char *path_a, RmPatternBitmask *mask_b,
const char *path_b) {
int result = 0;
int result_a = 0;
int result_b = 0;

if(RM_PATTERN_IS_CACHED(mask_a, idx)) {
/* Get the previous match result */
result = RM_PATTERN_GET_CACHED(mask_a, idx);
result_a = RM_PATTERN_GET_CACHED(mask_a, idx);
} else {
/* Match for the first time */
result = g_regex_match(regex, path_a, 0, NULL);
RM_PATTERN_SET_CACHED(mask_a, idx, result);
}

if(result) {
return -1;
result_a = g_regex_match(regex, path_a, 0, NULL);
RM_PATTERN_SET_CACHED(mask_a, idx, result_a);
}

if(RM_PATTERN_IS_CACHED(mask_b, idx)) {
/* Get the previous match result */
result = RM_PATTERN_GET_CACHED(mask_b, idx);
result_b = RM_PATTERN_GET_CACHED(mask_b, idx);
} else {
/* Match for the first time */
result = g_regex_match(regex, path_b, 0, NULL);
RM_PATTERN_SET_CACHED(mask_b, idx, result);
result_b = g_regex_match(regex, path_b, 0, NULL);
RM_PATTERN_SET_CACHED(mask_b, idx, result_b);
}

if(result) {
return +1;
}

/* Both match or none of the both match */
return 0;
return SIGN_DIFF(result_b, result_a);
}

/*
Expand Down

0 comments on commit 427791c

Please sign in to comment.