|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r48628 - trunk/tools/build/v2/util
From: grafikrobot_at_[hidden]
Date: 2008-09-06 01:09:21
Author: grafik
Date: 2008-09-06 01:09:20 EDT (Sat, 06 Sep 2008)
New Revision: 48628
URL: http://svn.boost.org/trac/boost/changeset/48628
Log:
Cleanup of BBv2 number utilities to improve performance.
Text files modified:
trunk/tools/build/v2/util/numbers.jam | 57 ++++++---------------------------------
1 files changed, 9 insertions(+), 48 deletions(-)
Modified: trunk/tools/build/v2/util/numbers.jam
==============================================================================
--- trunk/tools/build/v2/util/numbers.jam (original)
+++ trunk/tools/build/v2/util/numbers.jam 2008-09-06 01:09:20 EDT (Sat, 06 Sep 2008)
@@ -16,25 +16,9 @@
zero-test = is zero ; # if $(zero-test[$(n)]) == "is" "zero", n == 0
-local rule extend ( )
-{
- local next = $(digits[2-])$(znatural) ;
- natural += $(next) ;
- positive += $(next) ;
- incr += $(next) ;
- znatural = $(digits)$(znatural) ;
-}
-
-
rule trim-leading-zeroes ( value )
{
- local value2 = [ MATCH "^0(.*)$" : $(value) ] ;
- while $(value2)
- {
- value = $(value2) ;
- value2 = [ MATCH "^0(.*)$" : $(value) ] ;
- }
- return $(value:E="") ;
+ return [ CALC $(value) + 0 ] ;
}
@@ -76,45 +60,22 @@
if $(finish) != 0
{
- while ! $(positive[$(finish)])
- {
- extend ;
- }
-
- if $(step) = 1
+ local result ;
+ while [ less $(start) $(finish) ] || $(start) = $(finish)
{
- return $(positive[$(start)-$(finish)]) ;
- }
- else
- {
- local index = [ increment $(step) ] ;
- local by1 = $(positive[$(start)-$(finish)]) ;
- local result ;
- while $(by1)
- {
- result += $(by1[1]) ;
- by1 = $(by1[$(index)-]) ;
- }
- return $(result) ;
+ result += $(start) ;
+ start = [ CALC $(start) + $(step) ] ;
}
+ return $(result) ;
}
}
rule less ( n1 n2 )
{
- check $(n1) $(n2) ;
- n1 = [ trim-leading-zeroes $(n1) ] ;
- n2 = [ trim-leading-zeroes $(n2) ] ;
-
- # Avoid messy 0 case by appending 1.
- local l1 = [ range 2 [ log10 $(n1)1 ] ] ;
- local l2 = [ range 2 [ log10 $(n2)1 ] ] ;
-
- # Number of digits mismatch?
- if ( $(l1) < $(l2) ) || ( ( $(l1) = $(l2) ) && $(n1) < $(n2) )
+ switch [ CALC $(n2) - $(n1) ]
{
- return true ;
+ case [1-9]* : return true ;
}
}
@@ -184,7 +145,7 @@
assert.result 0 : trim-leading-zeroes 0 ;
assert.result 1234 : trim-leading-zeroes 1234 ;
assert.result 123456 : trim-leading-zeroes 0000123456 ;
- assert.result 10000123456 : trim-leading-zeroes 10000123456 ;
+ assert.result 1000123456 : trim-leading-zeroes 1000123456 ;
assert.result 10000 : trim-leading-zeroes 10000 ;
assert.result 10000 : trim-leading-zeroes 00010000 ;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk