forked from Shirakumo/trial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic-vector.lisp
33 lines (25 loc) · 1 KB
/
static-vector.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#|
This file is a part of trial
(c) 2017 Shirakumo http://tymoon.eu (shinmera@tymoon.eu)
Author: Nicolas Hafner <shinmera@tymoon.eu>
|#
(in-package #:org.shirakumo.fraf.trial)
(defvar *static-vector-map* (tg:make-weak-hash-table :weakness :key :test 'eq))
(declaim (inline mark-static-vector))
(defun mark-static-vector (vector)
(setf (gethash vector *static-vector-map*) T)
vector)
(defun make-static-vector (length &rest args)
(mark-static-vector (apply #'static-vectors:make-static-vector length args)))
(define-compiler-macro make-static-vector (length &rest args)
`(mark-static-vector (static-vectors:make-static-vector ,length ,@args)))
(declaim (inline static-vector-p))
(defun static-vector-p (vec)
(gethash vec *static-vector-map*))
(deftype static-vector ()
'(satisfies static-vector-p))
(declaim (inline maybe-free-static-vector))
(defun maybe-free-static-vector (vector)
(when (static-vector-p vector)
(static-vectors:free-static-vector vector)
(remhash vector *static-vector-map*)))