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 (assq lim c-laomib-cache))
	  ;; (elt (cons containing-sexp (cons start nil)))
	  (new-elt (list lim start end result))
	  big-ptr
	  (cur-ptr c-laomib-cache)
	  togo (size 0) cur-size
	  )
      (if 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)
	  (while (cdr cur-ptr)
	    (setq cur-size (- (nth 2 (cadr cur-ptr)) (car (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))))