Commit 17404091 authored by Stefan Monnier's avatar Stefan Monnier

(flymake-get-file-name-mode-and-masks)

(flymake-find-buildfile, flymake-find-possible-master-files)
(flymake-check-include, flymake-parse-line): Replace loops over the
length of lists, by loops over lists, to remove silly O(n�) behavior.
parent 4bd0a5d0
......@@ -269,13 +269,12 @@
"Return the corresponding entry from `flymake-allowed-file-name-masks'."
(unless (stringp file-name)
(error "Invalid file-name"))
(let ((count (length flymake-allowed-file-name-masks))
(idx 0)
(let ((fnm flymake-allowed-file-name-masks)
(mode-and-masks nil))
(while (and (not mode-and-masks) (< idx count))
(if (string-match (nth 0 (nth idx flymake-allowed-file-name-masks)) file-name)
(setq mode-and-masks (cdr (nth idx flymake-allowed-file-name-masks))))
(setq idx (1+ idx)))
(while (and (not mode-and-masks) fnm)
(if (string-match (car (car fnm)) file-name)
(setq mode-and-masks (cdr (car fnm))))
(setq fnm (cdr fnm)))
(flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks))
mode-and-masks))
......@@ -323,15 +322,13 @@ Return its file name if found, or nil if not found."
(flymake-get-buildfile-from-cache source-dir-name))
(let* ((buildfile-dir nil)
(buildfile nil)
(dir-count (length dirs))
(dir-idx 0)
(found nil))
(while (and (not found) (< dir-idx dir-count))
(setq buildfile-dir (concat source-dir-name (nth dir-idx dirs)))
(while (and (not found) dirs)
(setq buildfile-dir (concat source-dir-name (car dirs)))
(setq buildfile (concat buildfile-dir "/" buildfile-name))
(when (file-exists-p buildfile)
(setq found t))
(setq dir-idx (1+ dir-idx)))
(setq dirs (cdr dirs)))
(if found
(progn
(flymake-log 3 "found buildfile at %s/%s" buildfile-dir buildfile-name)
......@@ -412,31 +409,29 @@ Return t if so, nil if not."
Master files are .cpp and .c for and .h. Files are searched for
starting from the .h directory and max max-level parent dirs.
File contents are not checked."
(let* ((dir-idx 0)
(dir-count (length master-file-dirs))
(let* ((dirs master-file-dirs)
(files nil)
(done nil)
(masks-count (length masks)))
(while (and (not done) (< dir-idx dir-count))
(let* ((dir (concat (flymake-fix-file-name (file-name-directory file-name)) "/" (nth dir-idx master-file-dirs)))
(masks-idx 0))
(while (and (file-exists-p dir) (not done) (< masks-idx masks-count))
(let* ((mask (nth masks-idx masks))
(dir-files (directory-files dir t mask))
(file-count (length dir-files))
(file-idx 0))
(flymake-log 3 "dir %s, %d file(s) for mask %s" dir file-count mask)
(while (and (not done) (< file-idx file-count))
(when (not (file-directory-p (nth file-idx dir-files)))
(setq files (cons (nth file-idx dir-files) files))
(done nil))
(while (and (not done) dirs)
(let* ((dir (concat (flymake-fix-file-name (file-name-directory file-name))
"/" (car dirs)))
(masks masks))
(while (and (file-exists-p dir) (not done) masks)
(let* ((mask (car masks))
(dir-files (directory-files dir t mask)))
(flymake-log 3 "dir %s, %d file(s) for mask %s"
dir (length dir-files) mask)
(while (and (not done) dir-files)
(when (not (file-directory-p (car dir-files)))
(setq files (cons (car dir-files) files))
(when (>= (length files) flymake-master-file-count-limit)
(flymake-log 3 "master file count limit (%d) reached" flymake-master-file-count-limit)
(setq done t)))
(setq file-idx (1+ file-idx))))
(setq masks-idx (1+ masks-idx))))
(setq dir-idx (1+ dir-idx)))
(setq dir-files (cdr dir-files))))
(setq masks (cdr masks))))
(setq dirs (cdr dirs)))
(when files
(let ((flymake-included-file-name (file-name-nondirectory file-name)))
(setq files (sort files 'flymake-master-file-compare))))
......@@ -540,18 +535,17 @@ instead of reading master file from disk."
Return t if it can be found via include path using INC-PATH and INC-NAME."
(if (file-name-absolute-p inc-path)
(flymake-same-files source-file-name (concat inc-path "/" inc-name))
(let* ((count (length include-dirs))
(idx 0)
(file-name nil)
(let* ((file-name nil)
(found nil))
(while (and (not found) (< idx count))
(setq file-name (concat (file-name-directory source-file-name) "/" (nth idx include-dirs)))
(while (and (not found) include-dirs)
(setq file-name (concat (file-name-directory source-file-name)
"/" (car include-dirs)))
(if (> (length inc-path) 0)
(setq file-name (concat file-name "/" inc-path)))
(setq file-name (concat file-name "/" inc-name))
(when (flymake-same-files source-file-name file-name)
(setq found t))
(setq idx (1+ idx)))
(setq include-dirs (cdr include-dirs)))
found)))
(defun flymake-find-buffer-for-file (file-name)
......@@ -1026,18 +1020,17 @@ Return its components if so, nil if no."
(line-no 0)
(err-type "e")
(err-text nil)
(count (length flymake-err-line-patterns))
(idx 0)
(patterns flymake-err-line-patterns)
(matched nil))
(while (and (< idx count) (not matched))
(when (string-match (car (nth idx flymake-err-line-patterns)) line)
(let* ((file-idx (nth 1 (nth idx flymake-err-line-patterns)))
(line-idx (nth 2 (nth idx flymake-err-line-patterns))))
(while (and patterns (not matched))
(when (string-match (car (car patterns)) line)
(let* ((file-idx (nth 1 (car patterns)))
(line-idx (nth 2 (car patterns))))
(setq raw-file-name (if file-idx (match-string file-idx line) nil))
(setq line-no (if line-idx (string-to-int (match-string line-idx line)) 0))
(setq err-text (if (> (length (nth idx flymake-err-line-patterns)) 4)
(match-string (nth 4 (nth idx flymake-err-line-patterns)) line)
(setq err-text (if (> (length (car patterns)) 4)
(match-string (nth 4 (car patterns)) line)
(flymake-patch-err-text (substring line (match-end 0)))))
(or err-text (setq err-text "<no error text>"))
(if (and err-text (string-match "^[wW]arning" err-text))
......@@ -1046,7 +1039,7 @@ Return its components if so, nil if no."
(flymake-log 3 "parse line: file-idx=%s line-idx=%s file=%s line=%s text=%s" file-idx line-idx
raw-file-name line-no err-text)
(setq matched t)))
(setq idx (1+ idx)))
(setq patterns (cdr patterns)))
(if matched
(flymake-ler-make-ler raw-file-name line-no err-type err-text)
())))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment