Skip to content

Commit

Permalink
Merge pull request #8 from jbowes/reduce-pre-alloc
Browse files Browse the repository at this point in the history
Reduce allocs for pre information
  • Loading branch information
jbowes committed Oct 2, 2021
2 parents 729885f + ca96e0e commit ea0e189
Show file tree
Hide file tree
Showing 4 changed files with 369 additions and 1,389 deletions.
38 changes: 14 additions & 24 deletions constraint.rl
Expand Up @@ -17,35 +17,20 @@ import (
action start { s = p }
action numstart { numSeen = true }
action resetnum { numSeen = false; u = 0}
action partstart {
action partstart {
partalloc = new (struct{
str [2]string
uin [2]uint64
})

// optimize for eg "-rc.0"
cl.pre = make([]string, 0, 2)
cl.preNum = make([]uint64, 0, 2)
cl.pre = partalloc.str[:0]
cl.preNum = partalloc.uin[:0]
}

action num {
u *= 10
switch data[p] {
case '0':
case '1':
u += 1
case '2':
u += 2
case '3':
u += 3
case '4':
u += 4
case '5':
u += 5
case '6':
u += 6
case '7':
u += 7
case '8':
u += 8
case '9':
u += 9
}
u += uint64(data[p] - 48)
}

action major { cl.major = u }
Expand Down Expand Up @@ -237,6 +222,11 @@ func ParseConstraint(con string) (*Constraint, error) {
c := &alloc.c
c.clauses = alloc.cls[:0]

var partalloc *struct{
str [2]string
uin [2]uint64
}

%%write init;
%%write exec;

Expand Down
36 changes: 13 additions & 23 deletions version.rl
Expand Up @@ -18,34 +18,19 @@ import (
action numstart { numSeen = true }
action resetnum {numSeen = false; u = 0}
action partstart {
partalloc = new (struct{
str [2]string
uin [2]uint64
})

// optimize for eg "-rc.0"
v.pre = make([]string, 0, 2)
v.preNum = make([]uint64, 0, 2)
v.pre = partalloc.str[:0]
v.preNum = partalloc.uin[:0]
}

action num {
u *= 10
switch data[p] {
case '0':
case '1':
u += 1
case '2':
u += 2
case '3':
u += 3
case '4':
u += 4
case '5':
u += 5
case '6':
u += 6
case '7':
u += 7
case '8':
u += 8
case '9':
u += 9
}
u += uint64(data[p] - 48)
}

action major { v.major = u }
Expand Down Expand Up @@ -104,6 +89,11 @@ func Parse(ver string) (*Version, error) {
var u uint64
var numSeen bool

var partalloc *struct{
str [2]string
uin [2]uint64
}

v := &Version{}

%%write init;
Expand Down

0 comments on commit ea0e189

Please sign in to comment.