Skip to content

Commit

Permalink
chore: Replace stack collection with list
Browse files Browse the repository at this point in the history
  • Loading branch information
H1JK committed Nov 20, 2023
1 parent a6b816b commit b05cf14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 62 deletions.
56 changes: 0 additions & 56 deletions common/collections/stack.go

This file was deleted.

13 changes: 7 additions & 6 deletions rules/logic/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package logic

import (
"fmt"
list "github.com/bahlo/generic-list-go"
"regexp"
"strings"

"github.com/metacubex/mihomo/common/collections"
C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/rules/common"
)
Expand Down Expand Up @@ -133,7 +133,7 @@ func (logic *Logic) payloadToRule(subPayload string, parseRule ParseRuleFunc) (C
}

func (logic *Logic) format(payload string) ([]Range, error) {
stack := collections.NewStack()
stack := list.New[Range]()
num := 0
subRanges := make([]Range, 0)
for i, c := range payload {
Expand All @@ -144,15 +144,16 @@ func (logic *Logic) format(payload string) ([]Range, error) {
}

num++
stack.Push(sr)
stack.PushBack(sr)
} else if c == ')' {
if stack.Len() == 0 {
return nil, fmt.Errorf("missing '('")
}

sr := stack.Pop().(Range)
sr.end = i
subRanges = append(subRanges, sr)
sr := stack.Back()
stack.Remove(sr)
sr.Value.end = i
subRanges = append(subRanges, sr.Value)
}
}

Expand Down

0 comments on commit b05cf14

Please sign in to comment.