I am playing around with an encoder, something like encoding/gob or
encoding/json, and figured that the fastest way to figure out what
type the incoming interface{} is, as long as it is simple combination
of one of the builtin types, was a type switch.
So I started writing a type switch, but quickly realized that I wanted
to handle a LOT of cases. Not just all the ints and uints etc, but
also *ints and *uints, and []ints, []uints, *[]ints, []*ints, *[]*ints
etc etc ad nauseam.
So I created a small text/template that generates all these cases for
a HUGE switch statement.
Especially all the map cases take a lot of cases to express - what
with there being maps, pointers to maps, maps with pointer values,
pointer keys, pointer both ...
Anyway, the resulting switch statement is 3001 cases long, and the
file it lives in is 44325 lines, of which most is one function
containing the switch statement.
Compiling this package now takes time.
$ time go build
real 2m12.840s
user 2m9.947s
sys 0m1.776s
Why is this? It's not an uncommonly huge amount of code, even if the
function and switch size is probably fairly uncommon...
For the brave willing to duplicate this, the code can be found at
github.com/zond/godec.
To generate the source, "go run generator/generator.go", then just "go build".
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.