             (ar/bazel-qualified-package-path closest-build-file)
             (completing-read "build rule: " (ar/bazel-rule-names-in-build-file-path closest-build-file)))))
 
-(defun ar/bazel-build-rule-names (str)
-  "Return build rule names in STR."
-  (let ((start-pos))
-    ;; match all: name = "rulename"
-    (cl-loop for match-pos = (string-match "name *= *\"\\(.*\\)\"" str start-pos)
-             while match-pos
-             collect (match-string 1 str)
-             do (setf start-pos (1+ match-pos)))))
-
 (defun ar/bazel-rule-names-in-build-file-path (file-path)
   "Get rule names in build FILE-PATH."
-  (ar/bazel-build-rule-names (with-temp-buffer
-                               (insert-file-contents file-path)
-                               (buffer-string))))
+  (let ((rule-names))
+    (with-temp-buffer
+      (insert-file-contents file-path)
+      (goto-char 1)
+      ;; match all: name = "rulename"
+      (while (search-forward-regexp "name *= *\"\\(.*\\)\"" nil t 1)
+        (push (match-string-no-properties 1) rule-names)))
+    rule-names))
 
 (defun ar/bazel-qualified-rule-names-in-build-file-path (file-path)
   "Get qualified rule names in build FILE-PATH."

  "Get all workspace qualified rules.  If FRESH-READ, skip cache."
  (if fresh-read
      (let* ((counter 0)
             (build-files)
             (length))
        (setq build-files (ar/bazel-workspace-build-files))
        (setq length (length build-files))
        (seq-mapcat (lambda (build-file)
                      (setq counter (1+ counter))
                      (message "Reading (%d/%d) %s" counter length build-file)
                      (ar/bazel-qualified-rule-names-in-build-file-path build-file))
                    build-files))
    (ar/bazel--read-rules-cache)))

  "With a \"bazel\" prefix, we'd get linked directories like:
bazel-bin, bazel-genfiles, and bazel-out.")

(defvar ar/bazel-compile-subcommand "build" "Compile subcommand.")

(defun ar/bazel-compile ()
  "Invoke `'compile with `'completing-read a build rule in either current or parent directories."
  (interactive)
  (compile (format "%s %s" ar/bazel-command ar/bazel-compile-subcommand
                   ;; Use for narrowing down rules to closest package.
                   ;; (ar/bazel-completing-read-build-rule)
                   (completing-read "build rule: " (ar/bazel-workspace-build-rules)))))

(defun ar/bazel-completing-read-build-rule ()
  "Find a build file in current or parent directories and `'completing-read a build rule."
