From afb73269840042a99fa84dfd15ea0d3dc62f9ce7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alejandro=20R=20Sede=C3=B1o?= Date: Thu, 25 Apr 2013 14:34:13 -0400 Subject: [PATCH] wire-format: A more efficient VARINT-LENGTH --- wire-format.lisp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/wire-format.lisp b/wire-format.lisp index 2d80c81..0c1341d 100644 --- a/wire-format.lisp +++ b/wire-format.lisp @@ -1078,15 +1078,10 @@ (defun varint-length (val) "Return the length that 'val' will take when encoded as a varint integer." (declare #.$optimize-serialization) - (let ((val (ldb (byte 64 0) val)) - (size 0)) - (declare (type (unsigned-byte 64) val)) - (declare (type fixnum size)) - (loop do (setq val (ash val -7)) - (iincf size) - until (zerop val)) - size)) - + (loop repeat 10 ;max length of varint + do (setq val (ash val -7)) + count 1 + until (zerop val))) ;;; Skipping elements ;;; This is called at the lowest level, so arg types are assumed to be correct -- 2.45.2