2014-07-31 12:43:40 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"unsafe"
|
|
|
|
|
)
|
|
|
|
|
|
2015-04-11 10:01:54 +12:00
|
|
|
type slice struct {
|
2014-07-31 12:43:40 -07:00
|
|
|
array unsafe.Pointer
|
|
|
|
|
len int
|
|
|
|
|
cap int
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 09:18:59 -07:00
|
|
|
// maxElems is a lookup table containing the maximum capacity for a slice.
|
|
|
|
|
// The index is the size of the slice element.
|
|
|
|
|
var maxElems = [...]uintptr{
|
|
|
|
|
^uintptr(0),
|
|
|
|
|
_MaxMem / 1, _MaxMem / 2, _MaxMem / 3, _MaxMem / 4,
|
|
|
|
|
_MaxMem / 5, _MaxMem / 6, _MaxMem / 7, _MaxMem / 8,
|
|
|
|
|
_MaxMem / 9, _MaxMem / 10, _MaxMem / 11, _MaxMem / 12,
|
|
|
|
|
_MaxMem / 13, _MaxMem / 14, _MaxMem / 15, _MaxMem / 16,
|
|
|
|
|
_MaxMem / 17, _MaxMem / 18, _MaxMem / 19, _MaxMem / 20,
|
|
|
|
|
_MaxMem / 21, _MaxMem / 22, _MaxMem / 23, _MaxMem / 24,
|
|
|
|
|
_MaxMem / 25, _MaxMem / 26, _MaxMem / 27, _MaxMem / 28,
|
|
|
|
|
_MaxMem / 29, _MaxMem / 30, _MaxMem / 31, _MaxMem / 32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// maxSliceCap returns the maximum capacity for a slice.
|
|
|
|
|
func maxSliceCap(elemsize uintptr) uintptr {
|
|
|
|
|
if elemsize < uintptr(len(maxElems)) {
|
|
|
|
|
return maxElems[elemsize]
|
|
|
|
|
}
|
|
|
|
|
return _MaxMem / elemsize
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 14:17:52 +02:00
|
|
|
func makeslice(et *_type, len, cap int) slice {
|
2016-04-10 17:32:35 +02:00
|
|
|
// NOTE: The len > maxElements check here is not strictly necessary,
|
2014-07-31 12:43:40 -07:00
|
|
|
// but it produces a 'len out of range' error instead of a 'cap out of range' error
|
|
|
|
|
// when someone does make([]T, bignumber). 'cap out of range' is true too,
|
|
|
|
|
// but since the cap is only being supplied implicitly, saying len is clearer.
|
|
|
|
|
// See issue 4085.
|
2016-04-19 15:38:59 -07:00
|
|
|
maxElements := maxSliceCap(et.size)
|
2016-08-25 14:17:52 +02:00
|
|
|
if len < 0 || uintptr(len) > maxElements {
|
2014-07-31 12:43:40 -07:00
|
|
|
panic(errorString("makeslice: len out of range"))
|
|
|
|
|
}
|
2016-04-10 17:32:35 +02:00
|
|
|
|
2016-08-25 14:17:52 +02:00
|
|
|
if cap < len || uintptr(cap) > maxElements {
|
2014-07-31 12:43:40 -07:00
|
|
|
panic(errorString("makeslice: cap out of range"))
|
|
|
|
|
}
|
2016-04-10 17:32:35 +02:00
|
|
|
|
2016-04-19 19:35:10 -07:00
|
|
|
p := mallocgc(et.size*uintptr(cap), et, true)
|
2015-04-11 10:01:54 +12:00
|
|
|
return slice{p, len, cap}
|
2014-07-31 12:43:40 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 14:17:52 +02:00
|
|
|
func makeslice64(et *_type, len64, cap64 int64) slice {
|
|
|
|
|
len := int(len64)
|
|
|
|
|
if int64(len) != len64 {
|
|
|
|
|
panic(errorString("makeslice: len out of range"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cap := int(cap64)
|
|
|
|
|
if int64(cap) != cap64 {
|
|
|
|
|
panic(errorString("makeslice: cap out of range"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return makeslice(et, len, cap)
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-25 19:27:20 -04:00
|
|
|
// growslice handles slice growth during append.
|
2016-04-19 15:38:59 -07:00
|
|
|
// It is passed the slice element type, the old slice, and the desired new minimum capacity,
|
2015-06-25 19:27:20 -04:00
|
|
|
// and it returns a new slice with at least that capacity, with the old data
|
|
|
|
|
// copied into it.
|
cmd/compile: avoid a spill in append fast path
Instead of spilling newlen, recalculate it.
This removes a spill from the fast path,
at the cost of a cheap recalculation
on the (rare) growth path.
This uses 8 bytes less of stack space.
It generates two more bytes of code,
but that is due to suboptimal register allocation;
see far below.
Runtime append microbenchmarks are all over the map,
presumably due to incidental code movement.
Sample code:
func s(b []byte) []byte {
b = append(b, 1, 2, 3)
return b
}
Before:
"".s t=1 size=160 args=0x30 locals=0x48
0x0000 00000 (append.go:8) TEXT "".s(SB), $72-48
0x0000 00000 (append.go:8) MOVQ (TLS), CX
0x0009 00009 (append.go:8) CMPQ SP, 16(CX)
0x000d 00013 (append.go:8) JLS 149
0x0013 00019 (append.go:8) SUBQ $72, SP
0x0017 00023 (append.go:8) FUNCDATA $0, gclocals·6432f8c6a0d23fa7bee6c5d96f21a92a(SB)
0x0017 00023 (append.go:8) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0017 00023 (append.go:9) MOVQ "".b+88(FP), CX
0x001c 00028 (append.go:9) LEAQ 3(CX), DX
0x0020 00032 (append.go:9) MOVQ DX, "".autotmp_0+64(SP)
0x0025 00037 (append.go:9) MOVQ "".b+96(FP), BX
0x002a 00042 (append.go:9) CMPQ DX, BX
0x002d 00045 (append.go:9) JGT $0, 86
0x002f 00047 (append.go:8) MOVQ "".b+80(FP), AX
0x0034 00052 (append.go:9) MOVB $1, (AX)(CX*1)
0x0038 00056 (append.go:9) MOVB $2, 1(AX)(CX*1)
0x003d 00061 (append.go:9) MOVB $3, 2(AX)(CX*1)
0x0042 00066 (append.go:10) MOVQ AX, "".~r1+104(FP)
0x0047 00071 (append.go:10) MOVQ DX, "".~r1+112(FP)
0x004c 00076 (append.go:10) MOVQ BX, "".~r1+120(FP)
0x0051 00081 (append.go:10) ADDQ $72, SP
0x0055 00085 (append.go:10) RET
0x0056 00086 (append.go:9) LEAQ type.[]uint8(SB), AX
0x005d 00093 (append.go:9) MOVQ AX, (SP)
0x0061 00097 (append.go:9) MOVQ "".b+80(FP), BP
0x0066 00102 (append.go:9) MOVQ BP, 8(SP)
0x006b 00107 (append.go:9) MOVQ CX, 16(SP)
0x0070 00112 (append.go:9) MOVQ BX, 24(SP)
0x0075 00117 (append.go:9) MOVQ DX, 32(SP)
0x007a 00122 (append.go:9) PCDATA $0, $0
0x007a 00122 (append.go:9) CALL runtime.growslice(SB)
0x007f 00127 (append.go:9) MOVQ 40(SP), AX
0x0084 00132 (append.go:9) MOVQ 56(SP), BX
0x0089 00137 (append.go:8) MOVQ "".b+88(FP), CX
0x008e 00142 (append.go:9) MOVQ "".autotmp_0+64(SP), DX
0x0093 00147 (append.go:9) JMP 52
0x0095 00149 (append.go:9) NOP
0x0095 00149 (append.go:8) CALL runtime.morestack_noctxt(SB)
0x009a 00154 (append.go:8) JMP 0
After:
"".s t=1 size=176 args=0x30 locals=0x40
0x0000 00000 (append.go:8) TEXT "".s(SB), $64-48
0x0000 00000 (append.go:8) MOVQ (TLS), CX
0x0009 00009 (append.go:8) CMPQ SP, 16(CX)
0x000d 00013 (append.go:8) JLS 151
0x0013 00019 (append.go:8) SUBQ $64, SP
0x0017 00023 (append.go:8) FUNCDATA $0, gclocals·6432f8c6a0d23fa7bee6c5d96f21a92a(SB)
0x0017 00023 (append.go:8) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0017 00023 (append.go:9) MOVQ "".b+80(FP), CX
0x001c 00028 (append.go:9) LEAQ 3(CX), DX
0x0020 00032 (append.go:9) MOVQ "".b+88(FP), BX
0x0025 00037 (append.go:9) CMPQ DX, BX
0x0028 00040 (append.go:9) JGT $0, 81
0x002a 00042 (append.go:8) MOVQ "".b+72(FP), AX
0x002f 00047 (append.go:9) MOVB $1, (AX)(CX*1)
0x0033 00051 (append.go:9) MOVB $2, 1(AX)(CX*1)
0x0038 00056 (append.go:9) MOVB $3, 2(AX)(CX*1)
0x003d 00061 (append.go:10) MOVQ AX, "".~r1+96(FP)
0x0042 00066 (append.go:10) MOVQ DX, "".~r1+104(FP)
0x0047 00071 (append.go:10) MOVQ BX, "".~r1+112(FP)
0x004c 00076 (append.go:10) ADDQ $64, SP
0x0050 00080 (append.go:10) RET
0x0051 00081 (append.go:9) LEAQ type.[]uint8(SB), AX
0x0058 00088 (append.go:9) MOVQ AX, (SP)
0x005c 00092 (append.go:9) MOVQ "".b+72(FP), BP
0x0061 00097 (append.go:9) MOVQ BP, 8(SP)
0x0066 00102 (append.go:9) MOVQ CX, 16(SP)
0x006b 00107 (append.go:9) MOVQ BX, 24(SP)
0x0070 00112 (append.go:9) MOVQ DX, 32(SP)
0x0075 00117 (append.go:9) PCDATA $0, $0
0x0075 00117 (append.go:9) CALL runtime.growslice(SB)
0x007a 00122 (append.go:9) MOVQ 40(SP), AX
0x007f 00127 (append.go:9) MOVQ 48(SP), CX
0x0084 00132 (append.go:9) MOVQ 56(SP), BX
0x0089 00137 (append.go:9) ADDQ $3, CX
0x008d 00141 (append.go:9) MOVQ CX, DX
0x0090 00144 (append.go:8) MOVQ "".b+80(FP), CX
0x0095 00149 (append.go:9) JMP 47
0x0097 00151 (append.go:9) NOP
0x0097 00151 (append.go:8) CALL runtime.morestack_noctxt(SB)
0x009c 00156 (append.go:8) JMP 0
Observe that in the following sequence,
we should use DX directly instead of using
CX as a temporary register, which would make
the new code a strict improvement on the old:
0x007f 00127 (append.go:9) MOVQ 48(SP), CX
0x0084 00132 (append.go:9) MOVQ 56(SP), BX
0x0089 00137 (append.go:9) ADDQ $3, CX
0x008d 00141 (append.go:9) MOVQ CX, DX
0x0090 00144 (append.go:8) MOVQ "".b+80(FP), CX
Change-Id: I4ee50b18fa53865901d2d7f86c2cbb54c6fa6924
Reviewed-on: https://go-review.googlesource.com/21812
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2016-04-10 09:08:00 -07:00
|
|
|
// The new slice's length is set to the old slice's length,
|
|
|
|
|
// NOT to the new requested capacity.
|
|
|
|
|
// This is for codegen convenience. The old slice's length is used immediately
|
|
|
|
|
// to calculate where to write new values during an append.
|
|
|
|
|
// TODO: When the old backend is gone, reconsider this decision.
|
|
|
|
|
// The SSA backend might prefer the new length or to return only ptr/cap and save stack space.
|
2016-04-19 15:38:59 -07:00
|
|
|
func growslice(et *_type, old slice, cap int) slice {
|
2014-07-31 12:43:40 -07:00
|
|
|
if raceenabled {
|
2016-04-19 15:38:59 -07:00
|
|
|
callerpc := getcallerpc(unsafe.Pointer(&et))
|
|
|
|
|
racereadrangepc(old.array, uintptr(old.len*int(et.size)), callerpc, funcPC(growslice))
|
2014-07-31 12:43:40 -07:00
|
|
|
}
|
2015-10-21 11:04:42 -07:00
|
|
|
if msanenabled {
|
2016-04-19 15:38:59 -07:00
|
|
|
msanread(old.array, uintptr(old.len*int(et.size)))
|
2015-10-21 11:04:42 -07:00
|
|
|
}
|
2014-07-31 12:43:40 -07:00
|
|
|
|
|
|
|
|
if et.size == 0 {
|
2016-03-13 18:58:17 +01:00
|
|
|
if cap < old.cap {
|
|
|
|
|
panic(errorString("growslice: cap out of range"))
|
|
|
|
|
}
|
2015-03-11 12:07:50 -04:00
|
|
|
// append should not create a slice with nil pointer but non-zero len.
|
|
|
|
|
// We assume that append doesn't need to preserve old.array in this case.
|
2015-04-11 10:01:54 +12:00
|
|
|
return slice{unsafe.Pointer(&zerobase), old.len, cap}
|
2014-07-31 12:43:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newcap := old.cap
|
2016-03-24 01:55:42 +01:00
|
|
|
doublecap := newcap + newcap
|
|
|
|
|
if cap > doublecap {
|
2014-07-31 12:43:40 -07:00
|
|
|
newcap = cap
|
|
|
|
|
} else {
|
2016-03-24 01:55:42 +01:00
|
|
|
if old.len < 1024 {
|
|
|
|
|
newcap = doublecap
|
|
|
|
|
} else {
|
|
|
|
|
for newcap < cap {
|
2014-07-31 12:43:40 -07:00
|
|
|
newcap += newcap / 4
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-13 18:58:17 +01:00
|
|
|
|
2016-10-03 12:45:12 -07:00
|
|
|
var lenmem, newlenmem, capmem uintptr
|
2016-03-24 17:42:01 +01:00
|
|
|
const ptrSize = unsafe.Sizeof((*byte)(nil))
|
|
|
|
|
switch et.size {
|
|
|
|
|
case 1:
|
|
|
|
|
lenmem = uintptr(old.len)
|
2016-10-03 12:45:12 -07:00
|
|
|
newlenmem = uintptr(cap)
|
2016-03-24 17:42:01 +01:00
|
|
|
capmem = roundupsize(uintptr(newcap))
|
2016-03-13 18:58:17 +01:00
|
|
|
newcap = int(capmem)
|
2016-03-24 17:42:01 +01:00
|
|
|
case ptrSize:
|
|
|
|
|
lenmem = uintptr(old.len) * ptrSize
|
2016-10-03 12:45:12 -07:00
|
|
|
newlenmem = uintptr(cap) * ptrSize
|
2016-03-24 17:42:01 +01:00
|
|
|
capmem = roundupsize(uintptr(newcap) * ptrSize)
|
|
|
|
|
newcap = int(capmem / ptrSize)
|
|
|
|
|
default:
|
|
|
|
|
lenmem = uintptr(old.len) * et.size
|
2016-10-03 12:45:12 -07:00
|
|
|
newlenmem = uintptr(cap) * et.size
|
2016-03-24 17:42:01 +01:00
|
|
|
capmem = roundupsize(uintptr(newcap) * et.size)
|
2016-03-13 18:58:17 +01:00
|
|
|
newcap = int(capmem / et.size)
|
2016-03-24 17:42:01 +01:00
|
|
|
}
|
|
|
|
|
|
2017-08-05 13:44:25 +02:00
|
|
|
if cap < old.cap || capmem > _MaxMem {
|
2016-03-24 17:42:01 +01:00
|
|
|
panic(errorString("growslice: cap out of range"))
|
2016-03-13 18:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-31 12:43:40 -07:00
|
|
|
var p unsafe.Pointer
|
|
|
|
|
if et.kind&kindNoPointers != 0 {
|
2016-04-19 19:35:10 -07:00
|
|
|
p = mallocgc(capmem, nil, false)
|
2014-12-22 22:42:05 -05:00
|
|
|
memmove(p, old.array, lenmem)
|
2016-10-03 12:45:12 -07:00
|
|
|
// The append() that calls growslice is going to overwrite from old.len to cap (which will be the new length).
|
|
|
|
|
// Only clear the part that will not be overwritten.
|
2016-10-17 18:41:56 -04:00
|
|
|
memclrNoHeapPointers(add(p, newlenmem), capmem-newlenmem)
|
2014-07-31 12:43:40 -07:00
|
|
|
} else {
|
2015-06-11 16:49:38 +03:00
|
|
|
// Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan uninitialized memory.
|
2016-04-19 19:35:10 -07:00
|
|
|
p = mallocgc(capmem, et, true)
|
2015-11-13 17:45:22 -08:00
|
|
|
if !writeBarrier.enabled {
|
runtime: use memmove during slice append
The effect of this CL:
name old mean new mean delta
BinaryTree17 5.97s × (0.96,1.04) 5.95s × (0.98,1.02) ~ (p=0.697)
Fannkuch11 4.39s × (1.00,1.01) 4.41s × (1.00,1.01) +0.52% (p=0.015)
FmtFprintfEmpty 90.8ns × (0.97,1.05) 89.4ns × (0.94,1.13) ~ (p=0.571)
FmtFprintfString 305ns × (0.99,1.01) 292ns × (0.98,1.05) -4.35% (p=0.000)
FmtFprintfInt 278ns × (0.96,1.03) 279ns × (0.98,1.04) ~ (p=0.741)
FmtFprintfIntInt 489ns × (0.99,1.02) 482ns × (0.98,1.03) -1.43% (p=0.024)
FmtFprintfPrefixedInt 402ns × (0.98,1.02) 395ns × (0.98,1.03) -1.67% (p=0.014)
FmtFprintfFloat 578ns × (1.00,1.00) 569ns × (0.99,1.01) -1.48% (p=0.000)
FmtManyArgs 1.88µs × (0.99,1.01) 1.88µs × (1.00,1.01) ~ (p=0.055)
GobDecode 15.3ms × (0.99,1.01) 15.2ms × (1.00,1.01) -0.61% (p=0.007)
GobEncode 11.8ms × (0.98,1.05) 11.6ms × (0.99,1.01) ~ (p=0.075)
Gzip 647ms × (0.99,1.01) 647ms × (1.00,1.00) ~ (p=0.790)
Gunzip 143ms × (1.00,1.00) 142ms × (1.00,1.00) ~ (p=0.370)
HTTPClientServer 91.2µs × (0.99,1.01) 91.7µs × (0.99,1.02) ~ (p=0.233)
JSONEncode 31.5ms × (0.98,1.01) 31.8ms × (0.99,1.02) +1.09% (p=0.015)
JSONDecode 110ms × (0.99,1.01) 110ms × (0.99,1.02) ~ (p=0.577)
Mandelbrot200 6.00ms × (1.00,1.00) 6.02ms × (1.00,1.00) +0.24% (p=0.001)
GoParse 6.68ms × (0.98,1.02) 6.61ms × (0.99,1.01) -1.10% (p=0.027)
RegexpMatchEasy0_32 162ns × (1.00,1.00) 161ns × (1.00,1.01) -0.66% (p=0.001)
RegexpMatchEasy0_1K 539ns × (1.00,1.00) 539ns × (0.99,1.01) ~ (p=0.509)
RegexpMatchEasy1_32 140ns × (0.99,1.02) 139ns × (0.99,1.02) ~ (p=0.163)
RegexpMatchEasy1_1K 886ns × (1.00,1.00) 887ns × (1.00,1.00) ~ (p=0.408)
RegexpMatchMedium_32 252ns × (1.00,1.00) 255ns × (0.99,1.01) +1.01% (p=0.000)
RegexpMatchMedium_1K 72.6µs × (1.00,1.00) 72.6µs × (1.00,1.00) ~ (p=0.176)
RegexpMatchHard_32 3.84µs × (1.00,1.00) 3.84µs × (1.00,1.00) ~ (p=0.403)
RegexpMatchHard_1K 117µs × (1.00,1.00) 117µs × (1.00,1.00) ~ (p=0.351)
Revcomp 926ms × (0.99,1.01) 925ms × (0.99,1.01) ~ (p=0.541)
Template 126ms × (0.99,1.02) 130ms × (0.99,1.01) +3.42% (p=0.000)
TimeParse 632ns × (0.99,1.01) 626ns × (1.00,1.00) -0.88% (p=0.000)
TimeFormat 658ns × (0.99,1.01) 662ns × (0.99,1.02) ~ (p=0.111)
The effect of this CL combined with CL 9886:
name old mean new mean delta
BinaryTree17 5.90s × (0.98,1.03) 5.95s × (0.98,1.02) ~ (p=0.175)
Fannkuch11 4.34s × (1.00,1.00) 4.41s × (1.00,1.01) +1.69% (p=0.000)
FmtFprintfEmpty 87.3ns × (0.97,1.17) 89.4ns × (0.94,1.13) ~ (p=0.499)
FmtFprintfString 288ns × (0.98,1.04) 292ns × (0.98,1.05) ~ (p=0.292)
FmtFprintfInt 290ns × (0.98,1.05) 279ns × (0.98,1.04) -3.76% (p=0.001)
FmtFprintfIntInt 493ns × (0.98,1.04) 482ns × (0.98,1.03) -2.27% (p=0.017)
FmtFprintfPrefixedInt 399ns × (0.98,1.02) 395ns × (0.98,1.03) ~ (p=0.159)
FmtFprintfFloat 569ns × (1.00,1.00) 569ns × (0.99,1.01) ~ (p=0.847)
FmtManyArgs 1.90µs × (0.99,1.03) 1.88µs × (1.00,1.01) -1.14% (p=0.009)
GobDecode 15.2ms × (1.00,1.01) 15.2ms × (1.00,1.01) ~ (p=0.170)
GobEncode 11.8ms × (0.99,1.02) 11.6ms × (0.99,1.01) -1.47% (p=0.003)
Gzip 649ms × (0.99,1.00) 647ms × (1.00,1.00) ~ (p=0.200)
Gunzip 144ms × (0.99,1.01) 142ms × (1.00,1.00) -1.04% (p=0.000)
HTTPClientServer 91.1µs × (0.98,1.03) 91.7µs × (0.99,1.02) ~ (p=0.345)
JSONEncode 31.5ms × (0.99,1.01) 31.8ms × (0.99,1.02) +0.98% (p=0.021)
JSONDecode 110ms × (1.00,1.01) 110ms × (0.99,1.02) ~ (p=0.259)
Mandelbrot200 6.02ms × (1.00,1.01) 6.02ms × (1.00,1.00) ~ (p=0.500)
GoParse 6.68ms × (1.00,1.01) 6.61ms × (0.99,1.01) -1.17% (p=0.001)
RegexpMatchEasy0_32 161ns × (1.00,1.00) 161ns × (1.00,1.01) -0.39% (p=0.033)
RegexpMatchEasy0_1K 539ns × (1.00,1.00) 539ns × (0.99,1.01) ~ (p=0.445)
RegexpMatchEasy1_32 138ns × (1.00,1.01) 139ns × (0.99,1.02) ~ (p=0.281)
RegexpMatchEasy1_1K 887ns × (1.00,1.01) 887ns × (1.00,1.00) ~ (p=0.610)
RegexpMatchMedium_32 251ns × (1.00,1.02) 255ns × (0.99,1.01) +1.42% (p=0.000)
RegexpMatchMedium_1K 72.7µs × (1.00,1.00) 72.6µs × (1.00,1.00) ~ (p=0.097)
RegexpMatchHard_32 3.85µs × (1.00,1.00) 3.84µs × (1.00,1.00) -0.31% (p=0.000)
RegexpMatchHard_1K 117µs × (1.00,1.00) 117µs × (1.00,1.00) ~ (p=0.704)
Revcomp 923ms × (0.98,1.02) 925ms × (0.99,1.01) ~ (p=0.574)
Template 126ms × (0.98,1.03) 130ms × (0.99,1.01) +3.28% (p=0.000)
TimeParse 631ns × (0.99,1.02) 626ns × (1.00,1.00) ~ (p=0.053)
TimeFormat 660ns × (0.99,1.01) 662ns × (0.99,1.02) ~ (p=0.398)
Change-Id: I59c03d329fe7bc178a31477c6f1f01062b881041
Reviewed-on: https://go-review.googlesource.com/9993
Reviewed-by: Austin Clements <austin@google.com>
2015-05-13 10:48:05 -04:00
|
|
|
memmove(p, old.array, lenmem)
|
|
|
|
|
} else {
|
|
|
|
|
for i := uintptr(0); i < lenmem; i += et.size {
|
|
|
|
|
typedmemmove(et, add(p, i), add(old.array, i))
|
|
|
|
|
}
|
2014-12-22 22:42:05 -05:00
|
|
|
}
|
2014-07-31 12:43:40 -07:00
|
|
|
}
|
|
|
|
|
|
2015-04-11 10:01:54 +12:00
|
|
|
return slice{p, old.len, newcap}
|
2014-07-31 12:43:40 -07:00
|
|
|
}
|
|
|
|
|
|
2015-04-11 10:01:54 +12:00
|
|
|
func slicecopy(to, fm slice, width uintptr) int {
|
2014-12-30 12:31:17 -08:00
|
|
|
if fm.len == 0 || to.len == 0 {
|
2014-07-31 12:43:40 -07:00
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n := fm.len
|
|
|
|
|
if to.len < n {
|
|
|
|
|
n = to.len
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-30 12:31:17 -08:00
|
|
|
if width == 0 {
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-31 12:43:40 -07:00
|
|
|
if raceenabled {
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 21:59:49 -04:00
|
|
|
callerpc := getcallerpc(unsafe.Pointer(&to))
|
2014-09-03 11:10:38 -04:00
|
|
|
pc := funcPC(slicecopy)
|
2014-09-04 15:53:45 -04:00
|
|
|
racewriterangepc(to.array, uintptr(n*int(width)), callerpc, pc)
|
|
|
|
|
racereadrangepc(fm.array, uintptr(n*int(width)), callerpc, pc)
|
2014-07-31 12:43:40 -07:00
|
|
|
}
|
2015-10-21 11:04:42 -07:00
|
|
|
if msanenabled {
|
|
|
|
|
msanwrite(to.array, uintptr(n*int(width)))
|
|
|
|
|
msanread(fm.array, uintptr(n*int(width)))
|
|
|
|
|
}
|
2014-07-31 12:43:40 -07:00
|
|
|
|
|
|
|
|
size := uintptr(n) * width
|
|
|
|
|
if size == 1 { // common case worth about 2x to do here
|
|
|
|
|
// TODO: is this still worth it with new memmove impl?
|
|
|
|
|
*(*byte)(to.array) = *(*byte)(fm.array) // known to be a byte pointer
|
|
|
|
|
} else {
|
|
|
|
|
memmove(to.array, fm.array, size)
|
|
|
|
|
}
|
2016-02-29 15:01:00 -08:00
|
|
|
return n
|
2014-07-31 12:43:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func slicestringcopy(to []byte, fm string) int {
|
|
|
|
|
if len(fm) == 0 || len(to) == 0 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n := len(fm)
|
|
|
|
|
if len(to) < n {
|
|
|
|
|
n = len(to)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if raceenabled {
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 21:59:49 -04:00
|
|
|
callerpc := getcallerpc(unsafe.Pointer(&to))
|
2014-09-03 11:10:38 -04:00
|
|
|
pc := funcPC(slicestringcopy)
|
2014-09-04 15:53:45 -04:00
|
|
|
racewriterangepc(unsafe.Pointer(&to[0]), uintptr(n), callerpc, pc)
|
2014-07-31 12:43:40 -07:00
|
|
|
}
|
2015-10-21 11:04:42 -07:00
|
|
|
if msanenabled {
|
|
|
|
|
msanwrite(unsafe.Pointer(&to[0]), uintptr(n))
|
|
|
|
|
}
|
2014-07-31 12:43:40 -07:00
|
|
|
|
2016-02-29 15:01:00 -08:00
|
|
|
memmove(unsafe.Pointer(&to[0]), stringStructOf(&fm).str, uintptr(n))
|
2014-07-31 12:43:40 -07:00
|
|
|
return n
|
|
|
|
|
}
|