Skip to content

Commit

Permalink
use faster array concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
koresar committed Dec 10, 2024
1 parent 6711b63 commit 76beae0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions stampit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ export default (function () {
if (src === undefined) return dst;

// According to specification arrays must be concatenated.
// Also, the '.concat' creates a new array instance. Overrides the 'dst'.
if (Array.isArray(src)) return (Array.isArray(dst) ? dst : []).concat(src);

// Create a new array instance. Overrides the 'dst'.
if (Array.isArray(src)) {
if (Array.isArray(dst)) return [...dst, ...src];
return [...src]; // ignore the 'dst'
}
// Now deal with non plain 'src' object. 'src' overrides 'dst'
// Note that functions are also assigned! We do not deep merge functions.
if (!isPlainObject(src)) return src;
Expand Down Expand Up @@ -90,12 +92,12 @@ export default (function () {
function extractUniqueFunctions(...args) {
const funcs = new Set();
for (const arg of args) {
if (isFunction(arg)) {
funcs.add(arg);
} else if (Array.isArray(arg)) {
if (Array.isArray(arg)) {
for (const f of arg) {
if (isFunction(f)) funcs.add(f);
}
} else if (isFunction(arg)) {
funcs.add(arg);
}
}
return funcs.size ? Array.from(funcs) : undefined;
Expand Down

0 comments on commit 76beae0

Please sign in to comment.