Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit 21fc205

Browse files
committed
improve: fix double count on _count
1 parent 10e51ba commit 21fc205

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/engine.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ fn _match<S: StrDrive>(req: &Request<S>, state: &mut State, mut ctx: MatchContex
441441

442442
let mut count_ctx = ctx;
443443
count_ctx.skip_code(4);
444-
if _count(req, state, count_ctx, 1) == 0 {
444+
if _count(req, state, &mut count_ctx, 1) == 0 {
445445
state.marks.pop_discard();
446446
break 'result false;
447447
}
@@ -735,13 +735,13 @@ fn _match<S: StrDrive>(req: &Request<S>, state: &mut State, mut ctx: MatchContex
735735

736736
state.cursor = ctx.cursor;
737737

738-
let mut next_ctx = ctx;
739-
next_ctx.skip_code(4);
740-
let count = _count(req, state, next_ctx, max_count);
741-
ctx.skip_char::<S>(count);
738+
let mut count_ctx = ctx;
739+
count_ctx.skip_code(4);
740+
let count = _count(req, state, &mut count_ctx, max_count);
742741
if count < min_count {
743742
break 'result false;
744743
}
744+
ctx.cursor = count_ctx.cursor;
745745

746746
let next_code = ctx.peek_code(req, ctx.peek_code(req, 1) as usize + 1);
747747
if next_code == SreOpcode::SUCCESS as u32 && ctx.can_success(req) {
@@ -768,11 +768,11 @@ fn _match<S: StrDrive>(req: &Request<S>, state: &mut State, mut ctx: MatchContex
768768
} else {
769769
let mut count_ctx = ctx;
770770
count_ctx.skip_code(4);
771-
let count = _count(req, state, count_ctx, min_count);
771+
let count = _count(req, state, &mut count_ctx, min_count);
772772
if count < min_count {
773773
break 'result false;
774774
}
775-
ctx.skip_char::<S>(count);
775+
ctx.cursor = count_ctx.cursor;
776776
count as isize
777777
};
778778

@@ -845,11 +845,11 @@ fn _match<S: StrDrive>(req: &Request<S>, state: &mut State, mut ctx: MatchContex
845845
state.cursor = ctx.cursor;
846846
let mut count_ctx = ctx;
847847
count_ctx.skip_code(4);
848-
let count = _count(req, state, count_ctx, max_count);
848+
let count = _count(req, state, &mut count_ctx, max_count);
849849
if count < min_count {
850850
break 'result false;
851851
}
852-
ctx.skip_char::<S>(count);
852+
ctx.cursor = count_ctx.cursor;
853853
ctx.skip_code_from(req, 1);
854854
}
855855
SreOpcode::CHARSET
@@ -1324,7 +1324,7 @@ fn charset(set: &[u32], ch: u32) -> bool {
13241324
fn _count<S: StrDrive>(
13251325
req: &Request<S>,
13261326
state: &mut State,
1327-
mut ctx: MatchContext,
1327+
ctx: &mut MatchContext,
13281328
max_count: usize,
13291329
) -> usize {
13301330
let max_count = std::cmp::min(max_count, ctx.remaining_chars(req));
@@ -1347,28 +1347,28 @@ fn _count<S: StrDrive>(
13471347
}
13481348
}
13491349
SreOpcode::LITERAL => {
1350-
general_count_literal(req, &mut ctx, end, |code, c| code == c);
1350+
general_count_literal(req, ctx, end, |code, c| code == c);
13511351
}
13521352
SreOpcode::NOT_LITERAL => {
1353-
general_count_literal(req, &mut ctx, end, |code, c| code != c);
1353+
general_count_literal(req, ctx, end, |code, c| code != c);
13541354
}
13551355
SreOpcode::LITERAL_IGNORE => {
1356-
general_count_literal(req, &mut ctx, end, |code, c| code == lower_ascii(c));
1356+
general_count_literal(req, ctx, end, |code, c| code == lower_ascii(c));
13571357
}
13581358
SreOpcode::NOT_LITERAL_IGNORE => {
1359-
general_count_literal(req, &mut ctx, end, |code, c| code != lower_ascii(c));
1359+
general_count_literal(req, ctx, end, |code, c| code != lower_ascii(c));
13601360
}
13611361
SreOpcode::LITERAL_LOC_IGNORE => {
1362-
general_count_literal(req, &mut ctx, end, char_loc_ignore);
1362+
general_count_literal(req, ctx, end, char_loc_ignore);
13631363
}
13641364
SreOpcode::NOT_LITERAL_LOC_IGNORE => {
1365-
general_count_literal(req, &mut ctx, end, |code, c| !char_loc_ignore(code, c));
1365+
general_count_literal(req, ctx, end, |code, c| !char_loc_ignore(code, c));
13661366
}
13671367
SreOpcode::LITERAL_UNI_IGNORE => {
1368-
general_count_literal(req, &mut ctx, end, |code, c| code == lower_unicode(c));
1368+
general_count_literal(req, ctx, end, |code, c| code == lower_unicode(c));
13691369
}
13701370
SreOpcode::NOT_LITERAL_UNI_IGNORE => {
1371-
general_count_literal(req, &mut ctx, end, |code, c| code != lower_unicode(c));
1371+
general_count_literal(req, ctx, end, |code, c| code != lower_unicode(c));
13721372
}
13731373
_ => {
13741374
/* General case */
@@ -1383,7 +1383,7 @@ fn _count<S: StrDrive>(
13831383
..*state
13841384
};
13851385

1386-
while ctx.cursor.position < end && _match(req, &mut sub_state, ctx) {
1386+
while ctx.cursor.position < end && _match(req, &mut sub_state, *ctx) {
13871387
ctx.advance_char::<S>();
13881388
}
13891389
}

0 commit comments

Comments
 (0)