From 3aba6640c8a90ac657b02bcb3493203bad84f4e8 Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Wed, 30 May 2012 23:19:43 +0200 Subject: [PATCH] Allow specifying a growth threshold when creating a dynamic buffer --- src/sockets/dns/dynamic-buffer.lisp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/sockets/dns/dynamic-buffer.lisp b/src/sockets/dns/dynamic-buffer.lisp index 9ab9d55..6e7950e 100644 --- a/src/sockets/dns/dynamic-buffer.lisp +++ b/src/sockets/dns/dynamic-buffer.lisp @@ -6,9 +6,10 @@ (in-package :iolib.sockets) (defclass dynamic-buffer () - ((sequence :initform nil :accessor sequence-of) - (read-cursor :initform 0 :accessor read-cursor-of) - (write-cursor :initform 0 :accessor write-cursor-of))) + ((sequence :initform nil :accessor sequence-of) + (read-cursor :initform 0 :accessor read-cursor-of) + (write-cursor :initform 0 :accessor write-cursor-of) + (growth-threshold :initform 3/2 :accessor growth-threshold-of))) (defmethod initialize-instance :after ((buffer dynamic-buffer) &key (size 256) sequence (start 0) end) @@ -51,11 +52,12 @@ (defun maybe-grow-buffer (buffer vector) (with-accessors ((seq sequence-of) (size size-of) - (wcursor write-cursor-of)) + (wcursor write-cursor-of) + (threshold growth-threshold-of)) buffer (let ((vlen (length vector))) (when (< size (+ wcursor vlen)) - (let ((newsize (* 3/2 (+ size vlen)))) + (let ((newsize (* threshold (+ size vlen)))) (setf seq (adjust-array seq newsize)))))) (values buffer)) -- 2.11.4.GIT