GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): stop rebuilding the directory index on every ripgrep entry · anomalyco/opencode@2d1e6da

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/core/src/filesystem
    • search.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/filesystem/search.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/filesystem/search.ts
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ export const ripgrepLayer = Layer.effect(
2929
const scope = yield* Scope.Scope
3030
const state = {
3131
files: [] as string[],
32-
directories: [] as string[],
32+
directories: new Set<string>(),
3333
}
34-
const directories = new Set<string>()
3534
yield* ripgrep
3635
.find({
3736
cwd: location.directory,
@@ -40,9 +39,12 @@ export const ripgrepLayer = Layer.effect(
4039
onEntry: (entry) =>
4140
Effect.sync(() => {
4241
state.files.push(entry.path)
43-
const parts = entry.path.split("/")
44-
parts.slice(0, -1).forEach((_, index) => directories.add(parts.slice(0, index + 1).join("/") + path.sep))
45-
state.directories = Array.from(directories)
42+
// Directories accumulate in place; rebuilding the array per entry made this O(files * directories).
43+
let prefix = ""
44+
for (const part of entry.path.split("/").slice(0, -1)) {
45+
prefix = prefix ? `${prefix}/${part}` : part
46+
state.directories.add(prefix + path.sep)
47+
}
4648
}),
4749
})
4850
.pipe(Effect.orDie, Effect.asVoid, Effect.forkIn(scope))
@@ -104,7 +106,7 @@ export const ripgrepLayer = Layer.effect(
104106
input.type === "file"
105107
? state.files
106108
: input.type === "directory"
107-
? state.directories
109+
? [...state.directories]
108110
: [...state.files, ...state.directories]
109111
return fuzzysort.go(input.query, items, { limit: input.limit ?? 50 }).map((item) => {
110112
const relative = item.target

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.