scrapli / scrapligo

scrapli, but in go!
MIT License
259 stars 42 forks source link

readUntilPrompt should use byte.Contains instead of building RE out of string? #24

Closed hellt closed 3 years ago

hellt commented 3 years ago

@carlmontanari there is two methods readUntilPrompt defined in netconf and base channel packages

Those functions use RE compilation out of a prompt, which happens to be a string, not a RE. I think it makes it more performant to use bytes.Contains instead of matching RE compiled of a single string

https://github.com/scrapli/scrapligo/blob/6dd77b8af3c20e609560c051d5f73e4c54e55d6f/channel/base.go#L115-L138

carlmontanari commented 3 years ago

Gunna close per our chat offline.

For anyone else curious: tldr is that prompt (usually) coming from a user and is always a string, but can be a string that looks like a pattern. Users can pass this via send interactive for example. So we always wanna compile even if its not the most efficient thing. In hind sight it may have been better to have options for string pattern vs prompt pattern -- one of these days I may get around to doing that so it is more explicit and can just do the right thing vs just blindly compiling no mater what.