From: Chris Hanson Date: Tue, 19 Jan 1993 05:33:49 +0000 (+0000) Subject: Always grow string by fixed ratio to guarantee constant amortized cost X-Git-Tag: 20090517-FFI~8581 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=0447bda764b513580d448e2d377cd39df76daa4c;p=mit-scheme.git Always grow string by fixed ratio to guarantee constant amortized cost of insertion. --- diff --git a/v7/src/runtime/strout.scm b/v7/src/runtime/strout.scm index 89be585c3..92fa88ec4 100644 --- a/v7/src/runtime/strout.scm +++ b/v7/src/runtime/strout.scm @@ -1,8 +1,8 @@ #| -*-Scheme-*- -$Id: strout.scm,v 14.6 1993/01/18 16:50:09 gjr Exp $ +$Id: strout.scm,v 14.7 1993/01/19 05:33:49 cph Exp $ -Copyright (c) 1988-1993 Massachusetts Institute of Technology +Copyright (c) 1988-93 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -66,14 +66,15 @@ MIT in each case. |# accumulator counter) -(define (grow-accumulator! state min-n*) +(define (grow-accumulator! state min-size) (let* ((old (output-string-state/accumulator state)) (n (string-length old)) - (n* (+ n n)) - (new (make-string - (if (< n* min-n*) - min-n* - n*)))) + (new + (make-string + (let loop ((n (fix:+ n n))) + (if (fix:>= n min-size) + n + (loop (fix:+ n n))))))) (substring-move-left! old 0 n new 0) (set-output-string-state/accumulator! state new)))