On Thursday, August 4, 2016 at 2:19:06 PM UTC+8, Jesse McNelis wrote: > > On Thu, Aug 4, 2016 at 3:33 PM, T L <tapi...@gmail.com <javascript:>> > wrote: > > > > With some special memory optimizations for slice, I think it is possible > to > > make efficient conversions from []T to []interface. > > For example, we don't need to convert every element in []T to > interface{}, > > we can just use following struct to represent a special []interface{}, > > the concrete type of all interface{} values in the []interface{} is the > same > > one. > >> > >> type specialInterfaceSlice struct { > >> typ *_type > >> values []T > >> } > > > > That avoids the copy, but makes it impossible to take the address of > an interface{} in that []interface{}. >
Then how about adding a new field "inters []interfaceValue" in specialInterfaceSlice struct. At initial, it is blank, its elements will be created on needed. for example, to get element address. type specialInterfaceSlice struct { typ *_type values []T inters []interfaceValue } type interfaceValue struct { specialSlice *specialInterfaceSlice } then compiler can get the concrete type and value from interfaceValue.specialSlice -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.