emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/vlf d85f3d4 246/310: Fix access to uninitialized measur


From: Stefan Monnier
Subject: [elpa] externals/vlf d85f3d4 246/310: Fix access to uninitialized measurements when tuning.
Date: Sat, 28 Nov 2020 00:33:25 -0500 (EST)

branch: externals/vlf
commit d85f3d43fc838628cf27e7daec6c9507830337f3
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>

    Fix access to uninitialized measurements when tuning.
---
 vlf-tune.el | 46 ++++++++++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 18 deletions(-)

diff --git a/vlf-tune.el b/vlf-tune.el
index 677e881..7fcbfee 100644
--- a/vlf-tune.el
+++ b/vlf-tune.el
@@ -164,24 +164,34 @@ SIZE is number of bytes that are saved."
 
 (defun vlf-tune-assess (type coef index)
   "Get measurement value according to TYPE, COEF and INDEX."
-  (* coef (cond ((eq type :insert)
-                 (car (aref vlf-tune-insert-bps index)))
-                ((eq type :raw)
-                 (car (aref vlf-tune-insert-raw-bps index)))
-                ((eq type :encode) ;encode size is less than batch size
-                 (let ((closest-idx index)
-                       (val (car (aref vlf-tune-encode-bps index))))
-                   (while (and (zerop val) (not (zerop closest-idx)))
-                     (setq closest-idx (1- closest-idx)
-                           val (car (aref vlf-tune-encode-bps
-                                          closest-idx))))
-                   (/ (* val (1+ index)) (1+ closest-idx)))) ;approximate
-                ((eq type :write)
-                 (car (aref vlf-tune-write-bps index)))
-                ((eq type :hexl)
-                 (car (aref vlf-tune-hexl-bps index)))
-                ((eq type :dehexlify)
-                 (car (aref vlf-tune-dehexlify-bps index))))))
+  (* coef (or (cond ((eq type :insert)
+                     (if vlf-tune-insert-bps
+                         (car (aref vlf-tune-insert-bps index))))
+                    ((eq type :raw)
+                     (if vlf-tune-insert-raw-bps
+                         (car (aref vlf-tune-insert-raw-bps index))))
+                    ((eq type :encode) ;encode size is less than batch size
+                     (if vlf-tune-encode-bps
+                         (let ((closest-idx index)
+                               (val (car (aref vlf-tune-encode-bps
+                                               index))))
+                           (while (and (zerop val)
+                                       (not (zerop closest-idx)))
+                             (setq closest-idx (1- closest-idx)
+                                   val (car (aref vlf-tune-encode-bps
+                                                  closest-idx))))
+                           (/ (* val (1+ index)) ;approximate
+                              (1+ closest-idx)))))
+                    ((eq type :write)
+                     (if vlf-tune-write-bps
+                         (car (aref vlf-tune-write-bps index))))
+                    ((eq type :hexl)
+                     (if vlf-tune-hexl-bps
+                         (car (aref vlf-tune-hexl-bps index))))
+                    ((eq type :dehexlify)
+                     (if vlf-tune-dehexlify-bps
+                         (car (aref vlf-tune-dehexlify-bps index)))))
+              0)))
 
 (defun vlf-tune-score (types index)
   "Cumulative speed over TYPES which is alist of (type coef) for INDEX."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]