I have a string with underscores separating words (e.g. aaa_bbb_ccc)
I created a function to covert the string to camelCase (e.g. aaaBbbCcc).
I am wondering if there are some things that I am doing wrong which affect the performance. This is the code:
(defun underscore-to-camel (input)
(defparameter input-clean-capitalized (remove #\_ (string-capitalize input)))
(setf (aref input-clean-capitalized 0) (aref (string-downcase (aref input-clean-capitalized 0)) 0))
input-clean-capitalized)
I also created a second variant but it is ~25% slower (measured 3 million executions using time
):
(defun underscore-to-camel-v2 (input)
(defparameter input-clean-capitalized (remove #\_ (string-capitalize input)))
(concatenate
'string
(string-downcase (aref input-clean-capitalized 0))
(subseq input-clean-capitalized 1)))