Browse Source

The more readable code is even faster (#4702)

* Refactored the entire code to add add database bound handlers

* Updated `.travis.yml`

* Replaced the Dockerfile to update the dependencies (Linux, Roswell, Quicklibs, SBCL, …) to the (al)most recent versions

* Updated the Dockerfile. Reduced the image size from 491MB to 255MB

* Updated the Dockerfile again. Reduced the image size from 255MB to 191MB

* Optimised the code: The handler is now way more readable and even slightly faster albeit not much. Two libraries removed. I instructed the compiler to optimise for maximum speed.

This commit shoves another MB from the Docker image ;-)
Gert Thiel 6 years ago
parent
commit
b0579e622b
2 changed files with 18 additions and 34 deletions
  1. 6 3
      frameworks/Lisp/woo/helpers/starts-with.lisp
  2. 12 31
      frameworks/Lisp/woo/woo.ros

+ 6 - 3
frameworks/Lisp/woo/helpers/starts-with.lisp

@@ -1,3 +1,6 @@
-(defun starts-with (x starts)
-  (and (<= (length starts) (length x))
-       (string= x starts :end1 (length starts))))
+(defun starts-with (search-in search-for)
+  "Determine whether `str` starts with `search-for`"
+  (declare (string search-in)
+           (string search-for))
+  (and (<= (length search-for) (length search-in))
+       (string= search-in search-for :end1 (length search-for))))

+ 12 - 31
frameworks/Lisp/woo/woo.ros

@@ -17,15 +17,15 @@ exec ros -Q -- $0 "$@"
 
 ;; Woo - https://github.com/fukamachi/woo
 ;; Clack - https://github.com/fukamachi/clack
-;; Alexandria - https://github.com/keithj/alexandria
-;; Optima - https://github.com/m2ym/optima
 ;; Jonathan - https://github.com/fukamachi/jonathan
 ;; CL-MARKUP - https://github.com/arielnetworks/cl-markup
 ;; Postmodern - https://github.com/marijnh/Postmodern
 ;; QURI - https://github.com/fukamachi/quri
 
-(ql:quickload '(:alexandria :cl-markup :jonathan :optima :postmodern :quri :uiop :woo) :silent t)
-(use-package :optima)
+(ql:quickload '(:cl-markup :jonathan :postmodern :quri :uiop :woo) :silent t)
+
+
+(declaim (optimize (debug 0) (safety 0) (speed 3)))
 
 
 (load "./helpers/starts-with.lisp")
@@ -145,33 +145,14 @@ exec ros -Q -- $0 "$@"
    ))
 
 (defun handler (env)
-  "Woo router using Alexandria and Optima pattern matching"
-  (optima:match env
-    (
-      (guard (property :path-info path) (alexandria:starts-with-subseq "/plaintext" path))
-      (funcall 'plaintext)
-    )
-    (
-      (guard (property :path-info path) (alexandria:starts-with-subseq "/json" path))
-      (funcall 'json)
-    )
-    (
-      (guard (property :path-info path) (alexandria:starts-with-subseq "/db" path))
-      (funcall 'db)
-    )
-    (
-      (guard (property :path-info path) (alexandria:starts-with-subseq "/queries" path))
-      (funcall 'queries env)
-    )
-    (
-      (guard (property :path-info path) (alexandria:starts-with-subseq "/fortunes" path))
-      (funcall 'fortunes)
-    )
-    (
-      (guard (property :path-info path) (alexandria:starts-with-subseq "/updates" path))
-      (funcall 'updates env)
-    )
-  ))
+  "Woo router"
+  (let ((path (getf env :path-info)))
+    (cond ((starts-with path "/plaintext") (funcall 'plaintext  ))
+          ((starts-with path "/json"     ) (funcall 'json       ))
+          ((starts-with path "/db"       ) (funcall 'db         ))
+          ((starts-with path "/queries"  ) (funcall 'queries env))
+          ((starts-with path "/fortunes" ) (funcall 'fortunes   ))
+          ((starts-with path "/updates"  ) (funcall 'updates env)))))
 
 (defun main (&rest argv)
   "Create and start the server, applying argv to the env"