Get the QList size using Lisp instead of an external C function.
Sat Jan 30 16:40:15 CET 2010 Tobias Rautenkranz <tobias@rautenkranz.ch>
* Get the QList size using Lisp instead of an external C function.
diff -rN -u old-qt.core/src/lib/qlist.h new-qt.core/src/lib/qlist.h
--- old-qt.core/src/lib/qlist.h 2014-10-21 15:09:48.000000000 +0200
+++ new-qt.core/src/lib/qlist.h 2014-10-21 15:09:48.000000000 +0200
@@ -32,12 +32,6 @@
/** @internal
* size, free and make_list. */
#define DEFINE_QLIST_WRAPPER_ALL_PART(NAME, TYPE) \
-CL_SMOKE_QT_EXPORT int \
-cl_smoke_list_ ## NAME ## _size(const void* list) \
-{ \
- return static_cast<const QList< TYPE >*>(list)->size(); \
-} \
-\
CL_SMOKE_QT_EXPORT void \
cl_smoke_free_list_ ## NAME (void* list) \
{ \
diff -rN -u old-qt.core/src/list.lisp new-qt.core/src/list.lisp
--- old-qt.core/src/list.lisp 2014-10-21 15:09:48.000000000 +0200
+++ new-qt.core/src/list.lisp 2014-10-21 15:09:48.000000000 +0200
@@ -1,5 +1,24 @@
(in-package :cl-smoke.qt.core)
+(defbitfield qlist-data-flags
+ :sharable)
+
+(defcstruct qlist-data
+ (ref :char :count #.(class-size (find-class 'qt:basic-atomic-int)))
+ (alloc :int)
+ (begin :int)
+ (end :int)
+ (flags qlist-data-flags)
+ (array :pointer))
+
+(defcstruct qlist
+ (data (:pointer qlist-data)))
+
+(defun qlist-size (qlist)
+ (let ((data (foreign-slot-value qlist 'qlist 'data)))
+ (- (foreign-slot-value data 'qlist-data 'end)
+ (foreign-slot-value data 'qlist-data 'begin))))
+
(eval-when (:compile-toplevel :load-toplevel :execute)
(macrolet ((c-name (name)
`(nth-value 1 ,name))
@@ -22,8 +41,7 @@
,(third npp))))))
name-pre-post-fixes))
,@body)))
- (fun-names-let ((list-size "cl-smoke-list-" "-size")
- (list-free "cl-smoke-free-list-")
+ (fun-names-let ((list-free "cl-smoke-free-list-")
(list-make "cl-smoke-make-list-")
(list-at "cl-smoke-list-" "-at")
(list-append "cl-smoke-list-" "-append"))
@@ -35,9 +53,6 @@
`(progn
,(when (or (not c-name-p) def-cfuns)
`(progn
- (defcfun ,(c-name (list-size type)) :int
- "Returns the size of LIST."
- (list :pointer))
(defcfun ,(c-name (list-free type)) :void
"Frees LIST."
(list :pointer))
@@ -55,7 +70,8 @@
;; To Lisp
,@(loop for type-name in (ensure-list type-name) collect
`(defun ,(symbolicate 'from-list- type-name) (list-pointer)
- (let ((vector (make-array (,(list-size type)
+ (declare (optimize (speed 3)))
+ (let ((vector (make-array (qlist-size
list-pointer))))
(dotimes (index (length vector) vector)
(setf (elt vector index)