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

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

[elpa] master 16fa835 40/79: Optimize JSON parser.


From: Jackson Ray Hamilton
Subject: [elpa] master 16fa835 40/79: Optimize JSON parser.
Date: Sun, 14 Jun 2015 00:05:33 +0000

branch: master
commit 16fa8350ad55f8031b56e85ede473544d4485da8
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Optimize JSON parser.
---
 context-coloring.el           |   44 ++++++++++++++++++++++++++--------------
 test/context-coloring-test.el |    2 +-
 2 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index 4586832..753a7da 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -409,6 +409,7 @@ provide visually \"instant\" updates at 60 frames per 
second.")
            arg-string)
       (funcall callback arg-string))))
 
+;; TODO: These seem to spiral into an infinite loop sometimes.
 (defun context-coloring-elisp-parse-let-varlist (type)
   (let ((varlist '())
         syntax-code)
@@ -723,36 +724,47 @@ provide visually \"instant\" updates at 60 frames per 
second.")
     (save-excursion
       (context-coloring-elisp-colorize (point-min) (point-max)))))
 
-(defalias 'ccecb 'context-coloring-elisp-colorize-buffer)
-
 
 ;;; Shell command scopification / colorization
 
 (defun context-coloring-apply-tokens (tokens)
-  "Process a vector of TOKENS to apply context-based coloring to
+  "Process a list of TOKENS to apply context-based coloring to
 the current buffer.  Tokens are 3 integers: start, end, level.
-The vector is flat, with a new token occurring after every 3rd
+The list is flat, with a new token occurring after every 3rd
 element."
   (with-silent-modifications
-    (let ((i 0)
-          (len (length tokens)))
-      (while (< i len)
-        (context-coloring-colorize-region
-         (elt tokens i)
-         (elt tokens (+ i 1))
-         (elt tokens (+ i 2)))
-        (setq i (+ i 3))))
+    (while tokens
+      (context-coloring-colorize-region
+       (prog1 (car tokens) (setq tokens (cdr tokens)))
+       (prog1 (car tokens) (setq tokens (cdr tokens)))
+       (prog1 (car tokens) (setq tokens (cdr tokens)))))
     (context-coloring-maybe-colorize-comments-and-strings)))
 
 (defun context-coloring-parse-array (array)
   "Parse ARRAY as a flat JSON array of numbers."
-  (let ((braceless (substring (context-coloring-trim array) 1 -1)))
+  (let ((braceless (substring-no-properties (context-coloring-trim array) 1 
-1)))
     (cond
      ((> (length braceless) 0)
-      (vconcat
-       (mapcar 'string-to-number (split-string braceless ","))))
+      (let* (;; Use a leading comma to simplify the below loop's
+             ;; delimiter-checking.
+             (chars (vconcat (concat "," braceless)))
+             (index (length chars))
+             (number 0)
+             (multiplier 1)
+             numbers)
+        (while (> index 0)
+          (setq index (1- index))
+          (cond
+           ((= (elt chars index) context-coloring-COMMA-CHAR)
+            (setq numbers (cons number numbers))
+            (setq number 0)
+            (setq multiplier 1))
+           (t
+            (setq number (+ number (* (- (elt chars index) 48) multiplier)))
+            (setq multiplier (* multiplier 10)))))
+        numbers))
      (t
-      (vector)))))
+      (list)))))
 
 (defvar-local context-coloring-scopifier-process nil
   "The single scopifier process that can be running.")
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 5726421..a74ae6c 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -423,7 +423,7 @@ override it."
     (context-coloring-define-dispatch
      'define-dispatch-scopifier
      :modes '(context-coloring-test-define-dispatch-scopifier-mode)
-     :scopifier (lambda () (vector)))
+     :scopifier (lambda () (list)))
     (context-coloring-test-define-dispatch-scopifier-mode)
     (context-coloring-mode)
     (context-coloring-colorize)))



reply via email to

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