On Thursday, August 4, 2016 at 12:16:37 AM UTC+8, Ian Lance Taylor wrote:
>
> On Wed, Aug 3, 2016 at 9:12 AM, T L <[email protected] <javascript:>>
> wrote:
> >
> > On Wednesday, August 3, 2016 at 11:46:43 PM UTC+8, Axel Wagner wrote:
> >>
> >> True, but it would still be just the same loop, it wouldn't actually be
> >> significantly faster. And you'd need to put quite some machinery into a
> >> pretty rarely used functionality, which means it also wouldn't be
> cleaner.
> >>
> >> The thing is, that the memory representation of []T and []J, with J
> being
> >> an interface type, is very different form each other and differs also
> for
> >> each (T, J) pair, AIUI. So you can't really efficiently generalize
> this. The
> >> only thing it could possibly safe you, is writing the actual loop and
> in
> >> general go doesn't really do this kind of tradeoff (saving small
> amounts of
> >> trivial work by complicating the language and -implementation).
> >
> >
> > so the copy buitlin function is not essential?
>
> Correct.
>
> Although it is worth noting that, in the absence of significant
> compiler optimizations that the gc compiler does not currently
> implement, the copy builtin can be much more efficient than the
> ordinary user written loop; see
> https://golang.org/src/runtime/memmove_amd64.s. That is not true of a
> function that converts from []T to []interface.
>
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
> }
>
>
> Ian
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.