Просмотр исходного кода

goprotobuf: Fix bug in packed slice decoding.

R=adg
CC=golang-dev
http://codereview.appspot.com/4629089
David Symonds 14 лет назад
Родитель
Сommit
56eb29e5c4
1 измененных файлов с 3 добавлено и 23 удалено
  1. 3 23
      proto/decode.go

+ 3 - 23
proto/decode.go

@@ -420,17 +420,6 @@ func initSlice(pslice unsafe.Pointer, base uintptr) {
 	sp.Cap = startSize
 }
 
-// Make *pslice have base address base, length 0, and capacity max(startSize, n).
-func initSlicen(pslice unsafe.Pointer, base uintptr, n int) {
-	if n < startSize {
-		n = startSize
-	}
-	sp := (*reflect.SliceHeader)(pslice)
-	sp.Data = base
-	sp.Len = 0
-	sp.Cap = n
-}
-
 // Individual type decoders
 // For each,
 //	u is the decoded value,
@@ -538,10 +527,7 @@ func (o *Buffer) dec_slice_packed_bool(p *Properties, base uintptr, sbase uintpt
 
 	y := *x
 	if cap(y) == 0 {
-		// Packed fields are usually only encoded once,
-		// so this branch is almost always executed.
-		// The append in the loop below takes care of other cases.
-		initSlicen(unsafe.Pointer(x), sbase+p.scratch, nb)
+		initSlice(unsafe.Pointer(x), sbase+p.scratch)
 		y = *x
 	}
 
@@ -587,10 +573,7 @@ func (o *Buffer) dec_slice_packed_int32(p *Properties, base uintptr, sbase uintp
 
 	y := *x
 	if cap(y) == 0 {
-		// Packed fields are usually only encoded once,
-		// so this branch is almost always executed.
-		// The append in the loop below takes care of other cases.
-		initSlicen(unsafe.Pointer(x), sbase+p.scratch, nb)
+		initSlice(unsafe.Pointer(x), sbase+p.scratch)
 		y = *x
 	}
 
@@ -637,10 +620,7 @@ func (o *Buffer) dec_slice_packed_int64(p *Properties, base uintptr, sbase uintp
 
 	y := *x
 	if cap(y) == 0 {
-		// Packed fields are usually only encoded once,
-		// so this branch is almost always executed.
-		// The append in the loop below takes care of other cases.
-		initSlicen(unsafe.Pointer(x), sbase+p.scratch, nb)
+		initSlice(unsafe.Pointer(x), sbase+p.scratch)
 		y = *x
 	}