Skip to content

Commit 3e6ad00

Browse files
committed
perf: avoid calling uniq on array of hashes
closes #416 The comparison of `Hash` that is performed when calling `uniq` is significantly slower than traversing all duplicates and then calling `uniq` on an array of `String`.
1 parent cfdb0be commit 3e6ad00

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

vite_ruby/lib/vite_ruby/manifest.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def resolve_entries(*names, **options)
2828
entries = names.map { |name| lookup!(name, **options) }
2929
script_paths = entries.map { |entry| entry.fetch("file") }
3030

31-
imports = dev_server_running? ? [] : entries.flat_map { |entry| entry["imports"] }.compact.uniq
31+
imports = dev_server_running? ? [] : entries.flat_map { |entry| entry["imports"] }.compact
3232
{
3333
scripts: script_paths,
34-
imports: imports.map { |entry| entry.fetch("file") }.uniq,
34+
imports: imports.filter_map { |entry| entry.fetch("file") }.uniq,
3535
stylesheets: dev_server_running? ? [] : (entries + imports).flat_map { |entry| entry["css"] }.compact.uniq,
3636
}
3737
end

0 commit comments

Comments
 (0)