Commit 2f139bc
committed
nat: ParsePortSpec: prevent repeated parsing
This function constructs port-ranges, and validates the protocol. Calling
`NewPort` in a loop means it was parsing the port-spec multiple times. While
at it, also pre-allocate the slice that's used, making it ~28% faster, ~26%
fewer allocations, and ~15% less memory.
Before/after:
BenchmarkParsePortSpecs-10 73500 15198 ns/op 18248 B/op 359 allocs/op
BenchmarkParsePortSpecs-10 105000 10925 ns/op 15520 B/op 264 allocs/op
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>1 parent a5f5cb3 commit 2f139bc
1 file changed
Lines changed: 7 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
219 | | - | |
220 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
| |||
227 | 229 | | |
228 | 230 | | |
229 | 231 | | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | 232 | | |
236 | | - | |
| 233 | + | |
237 | 234 | | |
238 | 235 | | |
239 | 236 | | |
| |||
0 commit comments