Skip to content

Commit 64759af

Browse files
authored
refactor(regex): cache array conversion (#3152)
1 parent 8f6a380 commit 64759af

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

internal/regex_engine/compile.mbt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@ pub fn compile(profile~ : Profile, ast : Pattern) -> Regex {
3131
let tc = TranslateContext::new(ctx, symbol_table)
3232
let (expr, pref) = translate(tc, ast)
3333
let expr = enforce_pref(tc.ctx, First, pref, expr)
34-
Regex::new(profile, ctx, expr, tc.groups, symbol_table, symbol_repr)
34+
Regex::new(
35+
profile,
36+
ctx,
37+
expr,
38+
ReadOnlyArray::from_array(tc.groups),
39+
symbol_table,
40+
symbol_repr,
41+
)
3542
}

internal/regex_engine/regex.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Regex {
1717
profile : Profile
1818
ctx : @automata.Context
1919
expr : Expr
20-
groups : Array[String?]
20+
groups : ReadOnlyArray[String?]
2121
symbol_table : &@symbol_map.Table
2222
symbol_repr : ReadOnlyArray[Rechar]
2323
start_states : Array[(Category, State)]
@@ -26,15 +26,15 @@ struct Regex {
2626

2727
///|
2828
pub fn Regex::group_names(self : Regex) -> ReadOnlyArray[String?] {
29-
ReadOnlyArray::from_array(self.groups)
29+
self.groups
3030
}
3131

3232
///|
3333
fn Regex::new(
3434
profile : Profile,
3535
ctx : @automata.Context,
3636
expr : Expr,
37-
groups : Array[String?],
37+
groups : ReadOnlyArray[String?],
3838
symbol_table : &@symbol_map.Table,
3939
symbol_repr : ReadOnlyArray[Rechar],
4040
) -> Regex {

0 commit comments

Comments
 (0)