Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipe: fix v8 performance cliff for >10 case stmts #1585

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 7 additions & 35 deletions src/function.ts
Expand Up @@ -651,18 +651,7 @@ export function pipe(
ef?: Function,
fg?: Function,
gh?: Function,
hi?: Function,
ij?: Function,
jk?: Function,
kl?: Function,
lm?: Function,
mn?: Function,
no?: Function,
op?: Function,
pq?: Function,
qr?: Function,
rs?: Function,
st?: Function
hi?: Function
): unknown {
switch (arguments.length) {
case 1:
Expand All @@ -683,30 +672,13 @@ export function pipe(
return gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))
case 9:
return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))
case 10:
return ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))))
case 11:
return jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))))
case 12:
return kl!(jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))))))
case 13:
return lm!(kl!(jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))))))
case 14:
return mn!(lm!(kl!(jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))))))))
case 15:
return no!(mn!(lm!(kl!(jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))))))))
case 16:
return op!(no!(mn!(lm!(kl!(jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))))))))))
case 17:
return pq!(op!(no!(mn!(lm!(kl!(jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))))))))))
case 18:
return qr!(pq!(op!(no!(mn!(lm!(kl!(jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))))))))))))
case 19:
return rs!(qr!(pq!(op!(no!(mn!(lm!(kl!(jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))))))))))))
case 20:
return st!(rs!(qr!(pq!(op!(no!(mn!(lm!(kl!(jk!(ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))))))))))))))
default:
pbadenski marked this conversation as resolved.
Show resolved Hide resolved
let ret = arguments[0]
for (let i = 1; i < arguments.length; i++) {
ret = arguments[i](ret)
}
return ret
}
return
}

/**
Expand Down
3 changes: 1 addition & 2 deletions test/function.ts
Expand Up @@ -114,8 +114,7 @@ describe('function', () => {
U.deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f), 1023)
U.deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g), 2046)
U.deepStrictEqual(_.pipe(2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f), 2047)
// this is just to satisfy noImplicitReturns and 100% coverage
U.deepStrictEqual((_.pipe as any)(...[2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g]), undefined)
U.deepStrictEqual((_.pipe as any)(...[2, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g, f, g]), 4094)
})

it('getBooleanAlgebra', () => {
Expand Down