Rule: `avoidable-count`
These two are equivalent, as -1 means "to the end of the string". Avoiding the count call is however slightly more efficient, and should be preferred if performance is a concern.
r1 := substring(s, 3, count(s))
r2 := substring(s, 3, -1)
r1
+-------------------------------------------+------------+
| samples | 56862 |
| ns/op | 19973 |
| B/op | 12022 |
| allocs/op | 218 |
r2
+-------------------------------------------+------------+
| samples | 70899 |
| ns/op | 16716 |
| B/op | 10157 |
| allocs/op | 177 |
As @srenatus found some time back, the caching of numbers in OPA doesn't work as it was expected. Perhaps this issue would be less relevant if it did, and if that'll be the case later, we won't have to do this.
Coming back to this, I think it's too small to motivate a rule of its own. However, perhaps we could have a rule collect smaller optimizations within the scope of a single rule? Wouldn't necessarily all have to be about performance either, but cover any non-optimal use of built-ins like platform-dependent sprintf args, etc.
Rule name builtin-nitpicks? :)
With numbers now interned in OPA, there is no longer a need for this 🎉