]> asedeno.scripts.mit.edu Git - cl-protobufs.git/commitdiff
wire-format: A more efficient VARINT-LENGTH
authorAlejandro R Sedeño <asedeno@google.com>
Thu, 25 Apr 2013 18:34:13 +0000 (14:34 -0400)
committerAlejandro R Sedeño <asedeno@google.com>
Wed, 29 May 2013 22:02:01 +0000 (18:02 -0400)
wire-format.lisp

index 2d80c8189af28a17a486302aa5dda57d2f56276e..0c1341d320d9f38a096cfd77485649509b14bcb2 100644 (file)
 (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