From 3d6e80b447ef96cdac3aada1f2ca08073648294f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 12 Mar 2023 14:32:50 -0300 Subject: Tidy up different stuff --- str.lisp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'str.lisp') diff --git a/str.lisp b/str.lisp index 5116be4..aee3604 100644 --- a/str.lisp +++ b/str.lisp @@ -1,8 +1,8 @@ (in-package #:str) -(declaim (optimize (speed 3) (safety 1))) +(declaim (optimize speed)) -(declaim (ftype (function ((or pathname string)) (values string &optional)) read-file)) +(declaim (ftype (function ((or pathname string)) (values simple-string &optional)) read-file)) (defun read-file (path) (with-open-file (file path) (let* ((size (file-length file)) @@ -10,17 +10,17 @@ (read-sequence buf file) buf))) -(declaim (ftype (function (simple-string simple-string) (values (cons string) &optional)) split)) +(declaim (ftype (function (simple-string simple-string) (values (cons simple-string) &optional)) split)) (defun split (input delimiter) - (defun split-rec (result start) - (let ((next (search delimiter input :start2 start))) - (if next - (split-rec (queue:add result (subseq input start next)) (min (+ (length delimiter) next) - (length input))) - (queue:add result (subseq input start next))))) - (queue:to-list (split-rec (queue:new) 0))) + (labels ((split-rec (result start) + (let ((next (search delimiter input :start2 start))) + (if next + (split-rec (queue:add result (subseq input start next)) (min (the fixnum (+ (length delimiter) next)) + (the fixnum (length input)))) + (queue:add result (subseq input start next)))))) + (queue:to-list (split-rec (queue:new) 0)))) -(declaim (ftype (function ((cons character)) (values simple-string &optional)) from-list)) +(declaim (ftype (function ((or null (cons character))) (values simple-string &optional)) from-list)) (defun from-list (lst) (let ((str (make-string (length lst))) (i 0)) @@ -28,4 +28,3 @@ (setf (char str i) item) (incf i)) str)) - -- cgit v1.2.3