]> Cypherpunks repositories - gostls13.git/commitdiff
- fix performance bug (makeN always allocated a new vector)
authorRobert Griesemer <gri@golang.org>
Tue, 18 Aug 2009 18:48:47 +0000 (11:48 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 18 Aug 2009 18:48:47 +0000 (11:48 -0700)
- removed defs.go (moved declarations into arith.go where they belong)

R=r
DELTA=40  (16 added, 20 deleted, 4 changed)
OCL=33464
CL=33464

src/pkg/big/Makefile
src/pkg/big/arith.go
src/pkg/big/defs.go [deleted file]
src/pkg/big/nat.go

index b64ba40bf56edf1781fa85559e64858c40b04b95..8cf98911cb4a70c5423ec6ae47dd95d1fc2ee0e2 100644 (file)
@@ -6,7 +6,6 @@ include $(GOROOT)/src/Make.$(GOARCH)
 
 TARG=big
 GOFILES=\
-       defs.go\
        arith.go\
        big.go\
        nat.go\
index 04d0eb1bea15a55814aa5e0a519cd76558a50ed0..59f99e98d245eb4aedac6995c1a7ea484ca22af1 100644 (file)
@@ -10,6 +10,18 @@ package big
 
 import "unsafe"
 
+type Word uintptr
+
+const (
+       _S = uintptr(unsafe.Sizeof(Word));  // TODO(gri) should Sizeof return a uintptr?
+       _W = _S*8;
+       _B = 1<<_W;
+       _M = _B-1;
+       _W2 = _W/2;
+       _B2 = 1<<_W2;
+       _M2 = _B2-1;
+)
+
 
 // ----------------------------------------------------------------------------
 // Elementary operations on words
diff --git a/src/pkg/big/defs.go b/src/pkg/big/defs.go
deleted file mode 100644 (file)
index 5972fa6..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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 big
-
-import "unsafe"
-
-type Word uintptr
-
-const (
-       _S = uintptr(unsafe.Sizeof(Word));  // TODO(gri) should Sizeof return a uintptr?
-       _W = _S*8;
-       _B = 1<<_W;
-       _M = _B-1;
-       _W2 = _W/2;
-       _B2 = 1<<_W2;
-       _M2 = _B2-1;
-)
index 0274ceca597586ffdd04809ef8f40db45b8e2d88..ce9690442a2e581da228fa5a8d21e2a1d88401a1 100644 (file)
@@ -36,10 +36,14 @@ func normN(z []Word) []Word {
 func makeN(z []Word, m int, clear bool) []Word {
        if len(z) > m {
                z = z[0 : m];  // reuse z - has at least one extra word for a carry, if any
-               for i := range z {
-                       z[i] = 0;
+               if clear {
+                       for i := range z {
+                               z[i] = 0;
+                       }
                }
+               return z;
        }
+
        c := 4;  // minimum capacity
        if m > c {
                c = m;