From 8fc2a645c44c2e9f8f98cb167a1797e84dba196b Mon Sep 17 00:00:00 2001 From: kimory Date: Mon, 24 Oct 2022 00:41:04 +0200 Subject: [PATCH] Beginning of type declaration + optimization --- src/main.lisp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.lisp b/src/main.lisp index fcd262c..2940bb3 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -1,3 +1,4 @@ +(declaim (optimize (speed 3) (safety 3))) (defpackage :dodb (:use :common-lisp :util :osicat) ; TODO @@ -15,22 +16,38 @@ )) (in-package dodb) +(declaim (ftype (function (string) integer) filename->integer)) +(declaim (inline filename->integer)) (defun filename->integer (filename) + (declare (type string filename)) (parse-integer (pathname-name filename))) ; pathname-name returns the basename +(declaim (ftype (function (string) string) to-upper-case)) +(declaim (inline to-upper-case)) (defun to-upper-case (some-string) + (declare (type string some-string)) (format nil "~@:(~a~)" some-string)) ; Example: 18 -> 000000000000018 +(declaim (ftype (function (integer) string) number->filename)) +(declaim (inline number->filename)) (defun number->filename (number) + (declare (type integer number)) (format nil "~15,'0D" number)) +(declaim (ftype (function (character) boolean) is-forbidden-character-p)) +(declaim (inline is-forbidden-character-p)) (defun is-forbidden-character-p (some-char) + (declare (type character some-char)) (member some-char (list #\/ #\\))) +(declaim (ftype (function (string) string) protect-file-system)) +(declaim (inline protect-file-system)) (defun protect-file-system (value) + (declare (type string value)) (substitute-if #\_ #'is-forbidden-character-p value)) +; (declaim (ftype (function (string symbol null) string) value->safe-string)) (defun value->safe-string (value) (protect-file-system (typecase value (string value) @@ -68,7 +85,10 @@ :current-index current-index))) ; Example: returns "./storage/cars/indexes/by_name/". +(declaim (ftype (function (string string) string) db/index/get-directory-path)) +(declaim (inline db/index/get-directory-pathispatch)) (defun db/index/get-directory-path (dbpath index-name) + (declare (type string dbpath index-name)) (concatenate 'string dbpath "/indexes/by_" index-name "/")) ; Example: returns "./storage/cars/partitions/by_color/Red/".