diff options
| author | Stefan Monnier | 2005-03-25 00:17:42 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2005-03-25 00:17:42 +0000 |
| commit | 17404091a0619b2284db2d07f172b54a6ccaf6b7 (patch) | |
| tree | 38d99a5972e98b7672daa91ff97cf1b02553f046 | |
| parent | 4bd0a5d078287de216a0f3f0a6b546495a30afe2 (diff) | |
| download | emacs-17404091a0619b2284db2d07f172b54a6ccaf6b7.tar.gz emacs-17404091a0619b2284db2d07f172b54a6ccaf6b7.zip | |
(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.
| -rw-r--r-- | lisp/progmodes/flymake.el | 87 |
1 files changed, 40 insertions, 47 deletions
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 255be0ad3f3..1a5059776ed 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el | |||
| @@ -269,13 +269,12 @@ | |||
| 269 | "Return the corresponding entry from `flymake-allowed-file-name-masks'." | 269 | "Return the corresponding entry from `flymake-allowed-file-name-masks'." |
| 270 | (unless (stringp file-name) | 270 | (unless (stringp file-name) |
| 271 | (error "Invalid file-name")) | 271 | (error "Invalid file-name")) |
| 272 | (let ((count (length flymake-allowed-file-name-masks)) | 272 | (let ((fnm flymake-allowed-file-name-masks) |
| 273 | (idx 0) | ||
| 274 | (mode-and-masks nil)) | 273 | (mode-and-masks nil)) |
| 275 | (while (and (not mode-and-masks) (< idx count)) | 274 | (while (and (not mode-and-masks) fnm) |
| 276 | (if (string-match (nth 0 (nth idx flymake-allowed-file-name-masks)) file-name) | 275 | (if (string-match (car (car fnm)) file-name) |
| 277 | (setq mode-and-masks (cdr (nth idx flymake-allowed-file-name-masks)))) | 276 | (setq mode-and-masks (cdr (car fnm)))) |
| 278 | (setq idx (1+ idx))) | 277 | (setq fnm (cdr fnm))) |
| 279 | (flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks)) | 278 | (flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks)) |
| 280 | mode-and-masks)) | 279 | mode-and-masks)) |
| 281 | 280 | ||
| @@ -323,15 +322,13 @@ Return its file name if found, or nil if not found." | |||
| 323 | (flymake-get-buildfile-from-cache source-dir-name)) | 322 | (flymake-get-buildfile-from-cache source-dir-name)) |
| 324 | (let* ((buildfile-dir nil) | 323 | (let* ((buildfile-dir nil) |
| 325 | (buildfile nil) | 324 | (buildfile nil) |
| 326 | (dir-count (length dirs)) | ||
| 327 | (dir-idx 0) | ||
| 328 | (found nil)) | 325 | (found nil)) |
| 329 | (while (and (not found) (< dir-idx dir-count)) | 326 | (while (and (not found) dirs) |
| 330 | (setq buildfile-dir (concat source-dir-name (nth dir-idx dirs))) | 327 | (setq buildfile-dir (concat source-dir-name (car dirs))) |
| 331 | (setq buildfile (concat buildfile-dir "/" buildfile-name)) | 328 | (setq buildfile (concat buildfile-dir "/" buildfile-name)) |
| 332 | (when (file-exists-p buildfile) | 329 | (when (file-exists-p buildfile) |
| 333 | (setq found t)) | 330 | (setq found t)) |
| 334 | (setq dir-idx (1+ dir-idx))) | 331 | (setq dirs (cdr dirs))) |
| 335 | (if found | 332 | (if found |
| 336 | (progn | 333 | (progn |
| 337 | (flymake-log 3 "found buildfile at %s/%s" buildfile-dir buildfile-name) | 334 | (flymake-log 3 "found buildfile at %s/%s" buildfile-dir buildfile-name) |
| @@ -412,31 +409,29 @@ Return t if so, nil if not." | |||
| 412 | Master files are .cpp and .c for and .h. Files are searched for | 409 | Master files are .cpp and .c for and .h. Files are searched for |
| 413 | starting from the .h directory and max max-level parent dirs. | 410 | starting from the .h directory and max max-level parent dirs. |
| 414 | File contents are not checked." | 411 | File contents are not checked." |
| 415 | (let* ((dir-idx 0) | 412 | (let* ((dirs master-file-dirs) |
| 416 | (dir-count (length master-file-dirs)) | ||
| 417 | (files nil) | 413 | (files nil) |
| 418 | (done nil) | 414 | (done nil)) |
| 419 | (masks-count (length masks))) | 415 | |
| 420 | 416 | (while (and (not done) dirs) | |
| 421 | (while (and (not done) (< dir-idx dir-count)) | 417 | (let* ((dir (concat (flymake-fix-file-name (file-name-directory file-name)) |
| 422 | (let* ((dir (concat (flymake-fix-file-name (file-name-directory file-name)) "/" (nth dir-idx master-file-dirs))) | 418 | "/" (car dirs))) |
| 423 | (masks-idx 0)) | 419 | (masks masks)) |
| 424 | (while (and (file-exists-p dir) (not done) (< masks-idx masks-count)) | 420 | (while (and (file-exists-p dir) (not done) masks) |
| 425 | (let* ((mask (nth masks-idx masks)) | 421 | (let* ((mask (car masks)) |
| 426 | (dir-files (directory-files dir t mask)) | 422 | (dir-files (directory-files dir t mask))) |
| 427 | (file-count (length dir-files)) | 423 | |
| 428 | (file-idx 0)) | 424 | (flymake-log 3 "dir %s, %d file(s) for mask %s" |
| 429 | 425 | dir (length dir-files) mask) | |
| 430 | (flymake-log 3 "dir %s, %d file(s) for mask %s" dir file-count mask) | 426 | (while (and (not done) dir-files) |
| 431 | (while (and (not done) (< file-idx file-count)) | 427 | (when (not (file-directory-p (car dir-files))) |
| 432 | (when (not (file-directory-p (nth file-idx dir-files))) | 428 | (setq files (cons (car dir-files) files)) |
| 433 | (setq files (cons (nth file-idx dir-files) files)) | ||
| 434 | (when (>= (length files) flymake-master-file-count-limit) | 429 | (when (>= (length files) flymake-master-file-count-limit) |
| 435 | (flymake-log 3 "master file count limit (%d) reached" flymake-master-file-count-limit) | 430 | (flymake-log 3 "master file count limit (%d) reached" flymake-master-file-count-limit) |
| 436 | (setq done t))) | 431 | (setq done t))) |
| 437 | (setq file-idx (1+ file-idx)))) | 432 | (setq dir-files (cdr dir-files)))) |
| 438 | (setq masks-idx (1+ masks-idx)))) | 433 | (setq masks (cdr masks)))) |
| 439 | (setq dir-idx (1+ dir-idx))) | 434 | (setq dirs (cdr dirs))) |
| 440 | (when files | 435 | (when files |
| 441 | (let ((flymake-included-file-name (file-name-nondirectory file-name))) | 436 | (let ((flymake-included-file-name (file-name-nondirectory file-name))) |
| 442 | (setq files (sort files 'flymake-master-file-compare)))) | 437 | (setq files (sort files 'flymake-master-file-compare)))) |
| @@ -540,18 +535,17 @@ instead of reading master file from disk." | |||
| 540 | Return t if it can be found via include path using INC-PATH and INC-NAME." | 535 | Return t if it can be found via include path using INC-PATH and INC-NAME." |
| 541 | (if (file-name-absolute-p inc-path) | 536 | (if (file-name-absolute-p inc-path) |
| 542 | (flymake-same-files source-file-name (concat inc-path "/" inc-name)) | 537 | (flymake-same-files source-file-name (concat inc-path "/" inc-name)) |
| 543 | (let* ((count (length include-dirs)) | 538 | (let* ((file-name nil) |
| 544 | (idx 0) | ||
| 545 | (file-name nil) | ||
| 546 | (found nil)) | 539 | (found nil)) |
| 547 | (while (and (not found) (< idx count)) | 540 | (while (and (not found) include-dirs) |
| 548 | (setq file-name (concat (file-name-directory source-file-name) "/" (nth idx include-dirs))) | 541 | (setq file-name (concat (file-name-directory source-file-name) |
| 542 | "/" (car include-dirs))) | ||
| 549 | (if (> (length inc-path) 0) | 543 | (if (> (length inc-path) 0) |
| 550 | (setq file-name (concat file-name "/" inc-path))) | 544 | (setq file-name (concat file-name "/" inc-path))) |
| 551 | (setq file-name (concat file-name "/" inc-name)) | 545 | (setq file-name (concat file-name "/" inc-name)) |
| 552 | (when (flymake-same-files source-file-name file-name) | 546 | (when (flymake-same-files source-file-name file-name) |
| 553 | (setq found t)) | 547 | (setq found t)) |
| 554 | (setq idx (1+ idx))) | 548 | (setq include-dirs (cdr include-dirs))) |
| 555 | found))) | 549 | found))) |
| 556 | 550 | ||
| 557 | (defun flymake-find-buffer-for-file (file-name) | 551 | (defun flymake-find-buffer-for-file (file-name) |
| @@ -1026,18 +1020,17 @@ Return its components if so, nil if no." | |||
| 1026 | (line-no 0) | 1020 | (line-no 0) |
| 1027 | (err-type "e") | 1021 | (err-type "e") |
| 1028 | (err-text nil) | 1022 | (err-text nil) |
| 1029 | (count (length flymake-err-line-patterns)) | 1023 | (patterns flymake-err-line-patterns) |
| 1030 | (idx 0) | ||
| 1031 | (matched nil)) | 1024 | (matched nil)) |
| 1032 | (while (and (< idx count) (not matched)) | 1025 | (while (and patterns (not matched)) |
| 1033 | (when (string-match (car (nth idx flymake-err-line-patterns)) line) | 1026 | (when (string-match (car (car patterns)) line) |
| 1034 | (let* ((file-idx (nth 1 (nth idx flymake-err-line-patterns))) | 1027 | (let* ((file-idx (nth 1 (car patterns))) |
| 1035 | (line-idx (nth 2 (nth idx flymake-err-line-patterns)))) | 1028 | (line-idx (nth 2 (car patterns)))) |
| 1036 | 1029 | ||
| 1037 | (setq raw-file-name (if file-idx (match-string file-idx line) nil)) | 1030 | (setq raw-file-name (if file-idx (match-string file-idx line) nil)) |
| 1038 | (setq line-no (if line-idx (string-to-int (match-string line-idx line)) 0)) | 1031 | (setq line-no (if line-idx (string-to-int (match-string line-idx line)) 0)) |
| 1039 | (setq err-text (if (> (length (nth idx flymake-err-line-patterns)) 4) | 1032 | (setq err-text (if (> (length (car patterns)) 4) |
| 1040 | (match-string (nth 4 (nth idx flymake-err-line-patterns)) line) | 1033 | (match-string (nth 4 (car patterns)) line) |
| 1041 | (flymake-patch-err-text (substring line (match-end 0))))) | 1034 | (flymake-patch-err-text (substring line (match-end 0))))) |
| 1042 | (or err-text (setq err-text "<no error text>")) | 1035 | (or err-text (setq err-text "<no error text>")) |
| 1043 | (if (and err-text (string-match "^[wW]arning" err-text)) | 1036 | (if (and err-text (string-match "^[wW]arning" err-text)) |
| @@ -1046,7 +1039,7 @@ Return its components if so, nil if no." | |||
| 1046 | (flymake-log 3 "parse line: file-idx=%s line-idx=%s file=%s line=%s text=%s" file-idx line-idx | 1039 | (flymake-log 3 "parse line: file-idx=%s line-idx=%s file=%s line=%s text=%s" file-idx line-idx |
| 1047 | raw-file-name line-no err-text) | 1040 | raw-file-name line-no err-text) |
| 1048 | (setq matched t))) | 1041 | (setq matched t))) |
| 1049 | (setq idx (1+ idx))) | 1042 | (setq patterns (cdr patterns))) |
| 1050 | (if matched | 1043 | (if matched |
| 1051 | (flymake-ler-make-ler raw-file-name line-no err-type err-text) | 1044 | (flymake-ler-make-ler raw-file-name line-no err-type err-text) |
| 1052 | ()))) | 1045 | ()))) |