From d3e892bc2655fe0adc2d988f190bf866672f417d Mon Sep 17 00:00:00 2001 From: Nathan Froyd Subject: [PATCH 17/39] make LETTER-NEIGHBORS a SIMPLE-VECTOR --- src/lisp/structs.lisp | 40 +++++++++++++++++----------------------- 1 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/lisp/structs.lisp b/src/lisp/structs.lisp index 2d6b228..9b0a67b 100755 --- a/src/lisp/structs.lisp +++ b/src/lisp/structs.lisp @@ -15,11 +15,7 @@ (:print-function print-letter)) ;; represents a letter on the board. (value nil :type character) - (neighbors (make-array 8 - :fill-pointer 0 - :adjustable t - :element-type 'letter) - :type (vector letter *)) + (neighbors #() :type simple-vector) (used nil :type boolean)) (defstruct (board) @@ -74,24 +70,22 @@ ;; set up the neighbors for each letter (dotimes (y (board-rows board)) (dotimes (x (board-cols board)) - (let* ((letter (aref (aref bletters y) x)) - (neighbors (letter-neighbors letter)) - (ymax-ind (board-rows board)) - (xmax-ind (board-cols board))) - (loop for offsety from -1 to 1 - do (let ((yoi (+ y offsety))) - (when (and (>= yoi 0) (< yoi ymax-ind)) - (let ((row (aref bletters yoi))) - (loop for offsetx from -1 to 1 - unless (and (eql offsety 0) (eql offsetx 0)) - do (let ((xoi (+ x offsetx))) - (when (and (>= xoi 0) (< xoi xmax-ind)) - ;; now add the neighbor - (vector-push (aref row xoi) neighbors)))))))) - (setf (letter-neighbors letter) - neighbors) - (setf (aref (aref bletters y) x) - letter)))) + (loop with letter = (aref (aref bletters y) x) + with neighbors = nil + with ymax-ind = (board-rows board) + with xmax-ind = (board-cols board) + for offsety from -1 to 1 + do (let ((yoi (+ y offsety))) + (when (and (>= yoi 0) (< yoi ymax-ind)) + (let ((row (aref bletters yoi))) + (loop for offsetx from -1 to 1 + unless (and (eql offsety 0) (eql offsetx 0)) + do (let ((xoi (+ x offsetx))) + (when (and (>= xoi 0) (< xoi xmax-ind)) + ;; now add the neighbor + (push (aref row xoi) neighbors))))))) + finally (setf (letter-neighbors letter) + (coerce (nreverse neighbors) 'simple-vector))))) board)) -- 1.6.2