Review manual for loops in core:text/regex

This commit is contained in:
Feoramund
2024-08-05 03:49:29 -04:00
parent 14858309f0
commit 8f5b838a07
3 changed files with 8 additions and 6 deletions

View File

@@ -86,7 +86,7 @@ optimize_subtree :: proc(tree: Node, flags: common.Flags) -> (result: Node, chan
}
// Only recursive optimizations:
for i := 0; i < len(specific.nodes); i += 1 {
#no_bounds_check for i := 0; i < len(specific.nodes); i += 1 {
subnode, subnode_changes := optimize_subtree(specific.nodes[i], flags)
changes += subnode_changes
if subnode == nil {
@@ -194,7 +194,7 @@ optimize_subtree :: proc(tree: Node, flags: common.Flags) -> (result: Node, chan
new_range.lower = specific.runes[0]
new_range.upper = specific.runes[0]
for i := 1; i < len(specific.runes); i += 1 {
#no_bounds_check for i := 1; i < len(specific.runes); i += 1 {
r := specific.runes[i]
if new_range.lower == -1 {
new_range = { r, r }
@@ -228,7 +228,7 @@ optimize_subtree :: proc(tree: Node, flags: common.Flags) -> (result: Node, chan
//
// DO: `[aa-c]` => `[a-c]`
for range in specific.ranges {
for i := 0; i < len(specific.runes); i += 1 {
#no_bounds_check for i := 0; i < len(specific.runes); i += 1 {
r := specific.runes[i]
if range.lower <= r && r <= range.upper {
ordered_remove(&specific.runes, i)
@@ -244,7 +244,7 @@ optimize_subtree :: proc(tree: Node, flags: common.Flags) -> (result: Node, chan
// DO: `[a-cd-e]` => `[a-e]`
// DO: `[a-cb-e]` => `[a-e]`
slice.sort_by(specific.ranges[:], class_range_sorter)
for i := 0; i < len(specific.ranges) - 1; i += 1 {
#no_bounds_check for i := 0; i < len(specific.ranges) - 1; i += 1 {
for j := i + 1; j < len(specific.ranges); j += 1 {
left_range := &specific.ranges[i]
right_range := specific.ranges[j]

View File

@@ -225,7 +225,7 @@ null_denotation :: proc(p: ^Parser, token: Token) -> (result: Node, err: Error)
node := new(Node_Rune_Class)
for i := 0; i < len(token.text); /**/ {
#no_bounds_check for i := 0; i < len(token.text); /**/ {
r, size := utf8.decode_rune(token.text[i:])
if i == 0 && r == '^' {
node.negating = true
@@ -298,6 +298,8 @@ null_denotation :: proc(p: ^Parser, token: Token) -> (result: Node, err: Error)
}
if .Case_Insensitive in p.flags {
// These two loops cannot be in the form of `for x in y` because
// they append to the data that they iterate over.
length := len(node.runes)
#no_bounds_check for i := 0; i < length; i += 1 {
r := node.runes[i]

View File

@@ -291,7 +291,7 @@ match_and_allocate_capture :: proc(
context.allocator = permanent_allocator
num_groups := 0
for i := 0; i < len(saved); i += 2 {
#no_bounds_check for i := 0; i < len(saved); i += 2 {
a, b := saved[i], saved[i + 1]
if a == -1 || b == -1 {
continue