aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-25 22:11:15 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-25 22:11:15 -0700
commitf42663ce9acaaecf758349acae0c77aa6cac4e38 (patch)
treec0337d79f8ccbb65f8de4c797eb754e4ac6eabdc
parentc48f7e26635e02e7c7ddb30d3490754bda559733 (diff)
downloadbun-f42663ce9acaaecf758349acae0c77aa6cac4e38.tar.gz
bun-f42663ce9acaaecf758349acae0c77aa6cac4e38.tar.zst
bun-f42663ce9acaaecf758349acae0c77aa6cac4e38.zip
Avoid unnecessary copies
-rw-r--r--src/bun.js/bindings/JSBundlerPlugin.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/bun.js/bindings/JSBundlerPlugin.cpp b/src/bun.js/bindings/JSBundlerPlugin.cpp
index 1ac8b0c30..bff8ebd0d 100644
--- a/src/bun.js/bindings/JSBundlerPlugin.cpp
+++ b/src/bun.js/bindings/JSBundlerPlugin.cpp
@@ -58,16 +58,21 @@ void BundlerPlugin::NamespaceList::append(JSC::VM& vm, JSC::RegExp* filter, Stri
bool BundlerPlugin::anyMatchesCrossThread(const ZigString* namespaceStr, const ZigString* path, bool isOnLoad)
{
- auto namespaceString = namespaceStr ? Zig::toString(*namespaceStr) : String();
- auto pathString = Zig::toString(*path);
if (isOnLoad) {
+ if (this->onLoad.fileNamespace.isEmpty() && this->onLoad.namespaces.isEmpty())
+ return false;
+
+ // Avoid unnecessary string copies
+ auto namespaceString = namespaceStr ? Zig::toString(*namespaceStr) : String();
+
auto* group = this->onLoad.group(namespaceString);
if (group == nullptr) {
return false;
}
auto& filters = *group;
+ auto pathString = Zig::toString(*path);
for (auto& filter : filters) {
if (filter.match(pathString) > -1) {
@@ -76,11 +81,18 @@ bool BundlerPlugin::anyMatchesCrossThread(const ZigString* namespaceStr, const Z
}
} else {
+ if (this->onResolve.fileNamespace.isEmpty() && this->onResolve.namespaces.isEmpty())
+ return false;
+
+ // Avoid unnecessary string copies
+ auto namespaceString = namespaceStr ? Zig::toString(*namespaceStr) : String();
+
auto* group = this->onResolve.group(namespaceString);
if (group == nullptr) {
return false;
}
+ auto pathString = Zig::toString(*path);
auto& filters = *group;
for (auto& filter : filters) {