Skip to content

Commit 1bea28e

Browse files
committed
refactor: extract filename via lastIndexOf instead of split/pop
Replace split('/').pop() ?? '' with slice(lastIndexOf('/') + 1) in modelStore and nodeBookmarkStore. Equivalent across no-slash/trailing-slash/empty inputs and drops the nullish fallback branch.
1 parent 3377b8e commit 1bea28e

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/stores/modelStore.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export class ComfyModelDef {
6969
this.path_index = pathIndex
7070
this.file_name = name
7171
this.normalized_file_name = name.replaceAll('\\', '/')
72-
this.simplified_file_name = this.normalized_file_name.split('/').pop() ?? ''
72+
this.simplified_file_name = this.normalized_file_name.slice(
73+
this.normalized_file_name.lastIndexOf('/') + 1
74+
)
7375
if (this.simplified_file_name.endsWith('.safetensors')) {
7476
this.simplified_file_name = this.simplified_file_name.slice(
7577
0,

src/stores/nodeBookmarkStore.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export const useNodeBookmarkStore = defineStore('nodeBookmark', () => {
5050
.map((bookmark: string) => {
5151
if (bookmark.endsWith('/')) return createDummyFolderNodeDef(bookmark)
5252

53-
const parts = bookmark.split('/')
54-
const name = parts.pop() ?? ''
55-
const category = parts.join('/')
53+
const slashIndex = bookmark.lastIndexOf('/')
54+
const name = bookmark.slice(slashIndex + 1)
55+
const category = bookmark.slice(0, Math.max(0, slashIndex))
5656
const srcNodeDef = nodeDefStore.allNodeDefsByName[name]
5757
if (!srcNodeDef) {
5858
return null

0 commit comments

Comments
 (0)