From 6b67bfbcc1de5d1ad3690b1a9c360a11991819e5 Mon Sep 17 00:00:00 2001
From: David Botton
Date: Tue, 29 Dec 2020 22:31:26 -0500
Subject: [PATCH] Reduce extra object creations
---
clog-body.lisp | 15 +++++----
clog-document.lisp | 80 ++++++++++++++++++++++++++------------------
doc/clog-manual.html | 8 ++---
3 files changed, 59 insertions(+), 44 deletions(-)
diff --git a/clog-body.lisp b/clog-body.lisp
index 22416df..30b5e54 100644
--- a/clog-body.lisp
+++ b/clog-body.lisp
@@ -34,13 +34,14 @@
(defun make-clog-body (connection-id)
"Construct a new clog-body object."
- (make-instance
- 'clog-body
- :connection-id connection-id :html-id 0
- :window (make-clog-window connection-id)
- :html-document (make-clog-document connection-id)
- :location (make-clog-location connection-id)
- :navigator (make-clog-navigator connection-id)))
+ (let ((body (make-instance
+ 'clog-body
+ :connection-id connection-id :html-id 0
+ :window (make-clog-window connection-id)
+ :html-document (make-clog-document connection-id)
+ :location (make-clog-location connection-id)
+ :navigator (make-clog-navigator connection-id))))
+ (set-body (html-document body) body)))
;;;;;;;;;;;;
;; window ;;
diff --git a/clog-document.lisp b/clog-document.lisp
index 64481fe..bbe9a71 100644
--- a/clog-document.lisp
+++ b/clog-document.lisp
@@ -13,7 +13,15 @@
;; Implementation - clog-document
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defclass clog-document (clog-obj)()
+(defclass clog-document (clog-obj)
+ ((document-element
+ :reader document-element
+ :initarg :document-element)
+ (head-element
+ :reader head-element
+ :initarg :head-element)
+ (body-element
+ :reader body-element))
(:documentation "CLOG Document Objects encapsulate the document."))
;;;;;;;;;;;;;;;;;;;;;;;;
@@ -22,7 +30,45 @@
(defun make-clog-document (connection-id)
"Construct a new clog-document. (Private)"
- (make-instance 'clog-document :connection-id connection-id :html-id "document"))
+ (make-instance
+ 'clog-document :connection-id connection-id :html-id "document"
+ :document-element (make-instance 'clog-obj
+ :connection-id connection-id
+ :html-id "head")
+ :head-element (make-instance 'clog-obj
+ :connection-id connection-id
+ :html-id "documentElement")))
+;;;;;;;;;;;;;;;;;;;;;;
+;; document-element ;;
+;;;;;;;;;;;;;;;;;;;;;;
+
+(defgeneric document-element (clog-document)
+ (:documentation "Reader for Document Element object"))
+
+;;;;;;;;;;;;;;;;;;
+;; head-element ;;
+;;;;;;;;;;;;;;;;;;
+
+(defgeneric head-element (clog-document)
+ (:documentation "Reader for Head Element object"))
+
+;;;;;;;;;;;;;;;;;;
+;; body-element ;;
+;;;;;;;;;;;;;;;;;;
+
+(defgeneric document-element (clog-document)
+ (:documentation "Reader for Body Element object"))
+
+;;;;;;;;;;;;;;
+;; set-body ;;
+;;;;;;;;;;;;;;
+
+(defgeneric set-body (clog-document body)
+ (:documentation "Set the body slot after creating the
+clog-documentation object. (Private)"))
+
+(defmethod set-body ((obj clog-document) body)
+ (setf (slot-value obj 'body-element) body))
;;;;;;;;;;;;
;; domain ;;
@@ -90,36 +136,6 @@
(defmethod url ((obj clog-document))
(query obj "url"))
-;;;;;;;;;;;;;;;;;;;;;;
-;; document-element ;;
-;;;;;;;;;;;;;;;;;;;;;;
-
-(defgeneric document-element (clog-document)
- (:documentation "Get document-element."))
-
-(defmethod document-element ((obj clog-document))
- (make-instance 'clog-base :connection-id (connection-id obj) :html-id "documentElement"))
-
-;;;;;;;;;;;;;;;;;;
-;; head-element ;;
-;;;;;;;;;;;;;;;;;;
-
-(defgeneric head-element (clog-document)
- (:documentation "Get head-element."))
-
-(defmethod head-element ((obj clog-document))
- (make-instance 'clog-base :connection-id (connection-id obj) :html-id "head"))
-
-;;;;;;;;;;
-;; body ;;
-;;;;;;;;;;
-
-(defgeneric body-element (clog-document)
- (:documentation "Get body-element."))
-
-(defmethod body-element ((obj clog-document))
- (make-instance 'clog-base :connection-id (connection-id obj) :html-id "body"))
-
;;;;;;;;;;;;;;;;;
;; ready-state ;;
;;;;;;;;;;;;;;;;;
diff --git a/doc/clog-manual.html b/doc/clog-manual.html
index 8368093..f3b72ef 100644
--- a/doc/clog-manual.html
+++ b/doc/clog-manual.html
@@ -944,15 +944,13 @@ is nil unbind the event.
[generic-function] HEAD-ELEMENT CLOG-DOCUMENT
-Get head-element.
+Reader for Head Element object
@@ -960,7 +958,7 @@ is nil unbind the event.
[generic-function] DOCUMENT-ELEMENT CLOG-DOCUMENT
-Get document-element.
+Reader for Body Element object