On Friday, March 3, 2017 at 4:27:02 PM UTC+8, Konstantin Khomoutov wrote:
>
> On Thu, 2 Mar 2017 23:49:52 -0800 (PST)
> T L <[email protected] <javascript:>> wrote:
>
> > After all, the len and cap fields of any value of string and slice
> > values are immutable.
>
> Could you elaborate?
>
> Are you suggesting to replace
>
> var s []string
>
> if len(s) ...
> if cap(s) ...
>
> with
>
> if s.len ...
> if s.cap ...
>
> ?
>
> If yes, then what would be the prospective benefits?
>
No, I mean why not define string and slice as
type string struct {
underlyingString *struct {
data *byte
len int
}
}
type slice struct {
underlyingSlice *struct {
underlyingElements unsafe.Pointer
len int
cap int
}
}
instead of the current:
type string struct {
data *byte
len int
}
type slice struct {
underlyingElements unsafe.Pointer
len int
cap int
}
--
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.