Lines Matching full:re
96 @@ -122,6 +156,104 @@ func (p *parser) reuse(re *Regexp) {
97 p.free = re
100 +func (p *parser) checkLimits(re *Regexp) {
104 + p.checkSize(re)
105 + p.checkHeight(re)
108 +func (p *parser) checkSize(re *Regexp) {
118 + if re.Op == OpRepeat {
119 + n := re.Max
121 + n = re.Min
140 + for _, re := range p.stack {
141 + p.checkSize(re)
145 + if p.calcSize(re, true) > maxSize {
150 +func (p *parser) calcSize(re *Regexp, force bool) int64 {
152 + if size, ok := p.size[re]; ok {
158 + switch re.Op {
160 + size = int64(len(re.Rune))
163 + size = 2 + p.calcSize(re.Sub[0], false)
165 + size = 1 + p.calcSize(re.Sub[0], false)
167 + for _, sub := range re.Sub {
171 + for _, sub := range re.Sub {
174 + if len(re.Sub) > 1 {
175 + size += int64(len(re.Sub)) - 1
178 + sub := p.calcSize(re.Sub[0], false)
179 + if re.Max == -1 {
180 + if re.Min == 0 {
183 + size = 1 + int64(re.Min)*sub // xxx+
188 + size = int64(re.Max)*sub + int64(re.Max-re.Min)
194 + p.size[re] = size
198 func (p *parser) checkHeight(re *Regexp) {
201 @@ -158,6 +290,7 @@ func (p *parser) calcHeight(re *Regexp, force bool) int {
203 // push pushes the regexp re onto the parse stack and returns the regexp.
204 func (p *parser) push(re *Regexp) *Regexp {
205 + p.numRunes += len(re.Rune)
206 if re.Op == OpCharClass && len(re.Rune) == 2 && re.Rune[0] == re.Rune[1] {
208 if p.maybeConcat(re.Rune[0], p.flags&^FoldCase) {
209 @@ -189,7 +322,7 @@ func (p *parser) push(re *Regexp) *Regexp {
212 p.stack = append(p.stack, re)
213 - p.checkHeight(re)
214 + p.checkLimits(re)
215 return re
219 re.Sub = re.Sub0[:1]
220 re.Sub[0] = sub
221 p.stack[n-1] = re
222 - p.checkHeight(re)
223 + p.checkLimits(re)
225 if op == OpRepeat && (min >= 2 || max >= 2) && !repeatIsValid(re, 1000) {