cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: remove extra allocation when parsing x'val' literals

Open jordanlewis opened this issue 10 years ago • 3 comments

Scanning x'val' literals does an extra copy and allocation, since scanString returns a string that the literal parser just converts into bytes and back when using hex.DecodeString. Remove this extra work.

From @petermattis's comment on #7138:

It's mildly unfortunate for scanString to scan into a buf []byte, then convert that to a string before returning just so it can be passed to hex.DecodeString. It might be better to pass an additional flag to scanString so that we could call hex.Decode(buf) instead, avoiding an allocation and a copy. Also, it looks like hex.Decode(buf, buf) works as the writing to the output trails the input. This would avoid an additional allocation.

jordanlewis avatar Jun 10 '16 14:06 jordanlewis

Am starting out with golang and would be interested to work on this with some help if that is fine.

nexthack avatar Nov 01 '16 11:11 nexthack

Your submission is welcome - prepare a pull request following the contributing guidelines and one of us will be happy to review your code. Thanks!

jordanlewis avatar Nov 01 '16 14:11 jordanlewis

Working on this issue.Just for info.

nexthack avatar Nov 03 '16 20:11 nexthack