Function: c-laomib-put-cache

c-laomib-put-cache is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-laomib-put-cache LIM START END RESULT)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-laomib-put-cache (lim start end result)
  ;; Insert a new element into `c-laomib-cache', removing another element to
  ;; make room, if necessary.  The four parameters LIM, START, END, RESULT are
  ;; the components of the new element (see comment for `c-laomib-cache').
  ;; The return value is of no significance.
  (when lim
    (let (old-elt
	  (new-elt (list lim start end result))
	  big-ptr
	  (cur-ptr c-laomib-cache)
	  togo (size 0) cur-size)

      ;; If there is an elt which overlaps with the new element, remove it.
      (while
	  (and cur-ptr
	       (setq old-elt (car cur-ptr))
	       (or (not (eq (car old-elt) lim))
		   (not (and (> start (car (cddr old-elt)))
			     (<= start (cadr old-elt))))))
	(setq cur-ptr (cdr cur-ptr)))
      (when (and cur-ptr old-elt)
	(setq c-laomib-cache (delq old-elt c-laomib-cache)))

      (while (>= (length c-laomib-cache) 4)
	;; We delete the least recently used elt which doesn't enclose START,
	;; or ...
	(dolist (elt c-laomib-cache)
	  (if (or (<= start (cadr elt))
		  (> start (car (cddr elt))))
	      (setq togo elt)))

	;; ... delete the least recently used elt which isn't the biggest.
	(when (not togo)
	  (setq cur-ptr c-laomib-cache)
	  (while (cdr cur-ptr)
	    (setq cur-size (- (cadr (cadr cur-ptr))
			      (car (cddr (cadr cur-ptr)))))
	    (when (> cur-size size)
	      (setq size cur-size
		    big-ptr cur-ptr))
	    (setq cur-ptr (cdr cur-ptr)))
	  (setq togo (if (cddr big-ptr)
			 (car (last big-ptr))
		       (car big-ptr))))

	(setq c-laomib-cache (delq togo c-laomib-cache)))

      (push new-elt c-laomib-cache))))