cl-str icon indicating copy to clipboard operation
cl-str copied to clipboard

Improve correctness and function declarations

Open swapneils opened this issue 10 months ago • 2 comments

Correctness changes:

  • join now treats a nil separator as the empty string, rather than the string "nil", conforming to the semantics in the README of not converting nil to "nil".
  • containsp now automatically returns nil if either string input is nil.
  • alphanump and similar now use the correct regex checks for multi-line strings, rather than accepting an input if it has any line matching their specification.

Optimization changes:

  • Multiple non-recursive functions have been inlined
  • Multiple functions have ftype declarations
  • In local testing, there is a ~0.1s reduction from ~1.05s to ~0.95s in (time (dotimes (i 100) (with-output-to-string (throwaway) (let ((*standard-output* throwaway)) (asdf:test-system :str))))), despite the new tests in this version.
    • Note: Most of the tests use constantp inputs, so performance improvements here derive mainly from the inlining; they do not represent benefits from the ftype declarations in user-code.
    • Note: The comparison was specifically with the contents of https://github.com/vindarel/cl-str/pull/128, but that still shows an improvement over the original.

swapneils avatar Apr 20 '25 06:04 swapneils

excellent, thanks, it looks good, though I'll take more time to test in the wild, because merging bad type declarations can be very annoying (and imagine if Quicklisp releases in-between our quick fixes). I encourage anyone to try this PR.

vindarel avatar Apr 25 '25 21:04 vindarel

hey btw I have compilation warnings "deleting unreachable code" for the pad-* functions:

; in: DEFUN PAD-LEFT
;     (STR:PAD STR::LEN STR::S :PAD-SIDE :LEFT :PAD-CHAR STR::PAD-CHAR)
; --> BLOCK LET IF FLET STR::%PAD-CENTER BLOCK MULTIPLE-VALUE-BIND 
; --> MULTIPLE-VALUE-CALL FLOOR - 
; ==>
;   STR::LEN
; 
; note: deleting unreachable code

; --> BLOCK LET IF FLET STR::%PAD-RIGHT BLOCK CONCATENATE 
; ==>
;   STR::S
; 
; note: deleting unreachable code

[…]

Isn't there an issue when the arguments len s pad-char are the same than the mother pad function?

vindarel avatar May 06 '25 17:05 vindarel

I would do this:

(declaim (inline pad-left))
(defun pad-left (%len %s &key (%pad-char *pad-char*)) ;; %len
  (pad %len %s :pad-side :left :pad-char %pad-char))

;; same for pad-right

or remove their inline declaration. @swapneils ?

vindarel avatar Jul 27 '25 14:07 vindarel

Thanks for looking into the compile failures! I'll aim to check that change this weekend and see if a (few-months-old) source build of SBCL raises anything else. Been pretty busy with work and work-adjacent stuff the last few months.

swapneils avatar Aug 01 '25 09:08 swapneils

No more pad-* compilation warnings with a newer compiler (SBCL 2.5.8).

vindarel avatar Sep 04 '25 11:09 vindarel