Beginning of type declaration + optimization

This commit is contained in:
kimory 2022-10-24 00:41:04 +02:00
parent 88f1440fdb
commit 8fc2a645c4

View File

@ -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/".