From e8ede89e54a80862781e66665f98cbb5f7c4f31d Mon Sep 17 00:00:00 2001 From: Mohamed Hamed Date: Thu, 12 Feb 2026 21:33:59 +0100 Subject: [PATCH] perf: optimize 2-argument calls with direct string concatenation (#669) --- source/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/index.js b/source/index.js index 8bc993d..bf977df 100644 --- a/source/index.js +++ b/source/index.js @@ -151,8 +151,18 @@ const createStyler = (open, close, parent) => { const createBuilder = (self, _styler, _isEmpty) => { // Single argument is hot path, implicit coercion is faster than anything - // eslint-disable-next-line no-implicit-coercion - const builder = (...arguments_) => applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' ')); + const builder = (...arguments_) => { + if (arguments_.length === 1) { + // eslint-disable-next-line no-implicit-coercion + return applyStyle(builder, '' + arguments_[0]); + } + + if (arguments_.length === 2) { + return applyStyle(builder, arguments_[0] + ' ' + arguments_[1]); + } + + return applyStyle(builder, arguments_.join(' ')); + }; // We alter the prototype because we must return a function, but there is // no way to create a function with a different prototype