-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
increase perf && smaller size #23
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,16 @@ function toVal(mix) { | |
var k, y, str=''; | ||
|
||
if (typeof mix === 'string' || typeof mix === 'number') { | ||
str += mix; | ||
} else if (typeof mix === 'object') { | ||
return mix; | ||
} | ||
|
||
if (typeof mix === 'object') { | ||
if (Array.isArray(mix)) { | ||
for (k=0; k < mix.length; k++) { | ||
if (mix[k]) { | ||
if (y = toVal(mix[k])) { | ||
for (y=0; y < mix.length; y++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did these vars get swapped? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Codebase contains
thrice. I try to create more identical pieces of code for better work for the "deflate" algorithm. This trick saves 2 bytes of gzip size. I don't rename the third piece(https://github.com/lukeed/clsx/blob/master/src/index.js#L34) because the total size not changed. |
||
if (mix[y]) { | ||
if (k = toVal(mix[y])) { | ||
str && (str += ' '); | ||
str += y; | ||
str += k; | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression. Number type is returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests for this case. I found this is not regression :-) Because https://github.com/lukeed/clsx/blob/master/src/index.js#L35 converts
toVal
return value to string.