Commit 116b52d2 authored by Robert Griesemer's avatar Robert Griesemer

- fix performance bug (makeN always allocated a new vector)

- 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
parent ac5093fc
...@@ -6,7 +6,6 @@ include $(GOROOT)/src/Make.$(GOARCH) ...@@ -6,7 +6,6 @@ include $(GOROOT)/src/Make.$(GOARCH)
TARG=big TARG=big
GOFILES=\ GOFILES=\
defs.go\
arith.go\ arith.go\
big.go\ big.go\
nat.go\ nat.go\
......
...@@ -10,6 +10,18 @@ package big ...@@ -10,6 +10,18 @@ package big
import "unsafe" 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 // Elementary operations on words
......
// 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;
)
...@@ -36,10 +36,14 @@ func normN(z []Word) []Word { ...@@ -36,10 +36,14 @@ func normN(z []Word) []Word {
func makeN(z []Word, m int, clear bool) []Word { func makeN(z []Word, m int, clear bool) []Word {
if len(z) > m { if len(z) > m {
z = z[0 : m]; // reuse z - has at least one extra word for a carry, if any z = z[0 : m]; // reuse z - has at least one extra word for a carry, if any
for i := range z { if clear {
z[i] = 0; for i := range z {
z[i] = 0;
}
} }
return z;
} }
c := 4; // minimum capacity c := 4; // minimum capacity
if m > c { if m > c {
c = m; c = m;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment