gokogiri icon indicating copy to clipboard operation
gokogiri copied to clipboard

Encoding is passed around as byte array instead of string

Open jbowtie opened this issue 11 years ago • 5 comments

There doesn't seem to be any particular reason that encoding names are passed around as byte arrays instead of strings. This results in a lot of unnecessary conversion back and forth (particularly in light of Go and libxml2 both using UTF-8 internally).

I propose we modify the API to rectify this; it will simplify things for the user.

jbowtie avatar Jan 07 '14 02:01 jbowtie

Hmmmm, I wonder, @hcatlin, do you remember why the choice was made to make the encoding inputs byte arrays instead of strings?

mdayaram avatar Jan 07 '14 06:01 mdayaram

Zhigang believed this was better for memory management and casting to C.

On Mon, Jan 6, 2014 at 10:49 PM, Manoj Dayaram [email protected]:

Hmmmm, I wonder, @hcatlin https://github.com/hcatlin, do you remember why the choice was made to make the encoding inputs byte arrays instead of strings?

— Reply to this email directly or view it on GitHubhttps://github.com/moovweb/gokogiri/issues/68#issuecomment-31716871 .

HamptonMakes avatar Jan 07 '14 17:01 HamptonMakes

That doesn't seem to be the case - particularly as we store input and output encodings separately (and in typical usage these are only set and/or consulted once per document).

The only benefit to retaining them as bytes in the API would be backwards compatibility, and I'd expect that most users are passing nil most of the time anyway rather than deal with Go's lack of built-in encoding support.

jbowtie avatar Jan 07 '14 21:01 jbowtie

I'm fine with updating the API, specially since all errors would be flagged at compile time and are easily fixed by typecasting to string anyways.

As long as we're sure there's no performance hit, I'm ok with it. @jbowtie, if you want to write a PR for this I'll be happy to review.

mdayaram avatar Jan 10 '14 02:01 mdayaram

It's fairly low down on my priority list but would be a great place for a new contributor to start.

jbowtie avatar Jan 14 '14 21:01 jbowtie