On Sun, Oct 6, 2013 at 3:42 AM, Luís Oliveira loliveira@common-lisp.net wrote:
On Sun, Oct 6, 2013 at 12:36 AM, Liam Healy lnp@healy.washington.dc.us wrote:
Having the foreign-string-alloc call lisp-string-to-foreign would cause the string length to be calculated twice. But it indeed seems like they could both share a helper function at least.
Are you sure?
;;; LMH new function (defun length-of-string-as-foreign (string encoding start end null-terminated-p) (+ (funcall (octet-counter (lookup-mapping *foreign-string-mappings* encoding))
[...]
;;; LMH new version (defun foreign-string-alloc (string &key (encoding *default-foreign-encoding*) (null-terminated-p t) (start 0) end)
[...]
(lisp-string-to-foreign string ptr length :start start :end end :encoding encoding)
[...]
The only duplication of effort is mapping and null-len, which seem like pretty lightweight operations.
This version of foreign-string-alloc calls the octet-counter function twice. Once via length-of-string-as-foreign then again via lisp-string-to-foreign.
Cheers,
-- Luís Oliveira http://kerno.org/~luis/
Is that important? octect-counter is a slot lookup. I've always considered slots the equivalent of ordinary variables, so this seems at least as efficient as the alternatives.
Liam