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

Code golf diffChildren size down by 33 B ⛳️ #1580

Merged
merged 6 commits into from
Apr 28, 2019
Merged

Code golf diffChildren size down by 33 B ⛳️ #1580

merged 6 commits into from
Apr 28, 2019

Conversation

jviide
Copy link
Contributor

@jviide jviide commented Apr 26, 2019

This pull request reduces the gzipped code size by 33 bytes by progressively refactoring diffChildren. The commits are roughly in an increasing order of weirdness, so just some of them can be cherry-picked if needed.

  • 65dfda6, d676eba Do pretty run-of-the mill refactoring to avoid comparisons (-9 B)
  • 5a9ad93 Avoids two break statements (-7 B)
  • f9bc8c5 Refactors out local variables p and index, with hopefully sufficient comments explaining the logic (-13 B)
  • 7b3606d Compresses code by assuming that EMPTY_OBJ._children is undefined (-4 B)

These changes conflict a bit with @andrewiggins's #1578, sorry about that.

@coveralls
Copy link

coveralls commented Apr 26, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling de71c11 on jviide:golf-diff into 47656bc on developit:master.

@jviide jviide changed the title Code gold diffChildren size down by 33 B ⛳️ Code golf diffChildren size down by 33 B ⛳️ Apr 26, 2019
Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wonderfull, also clearly documented as to how and why you replaced it. Thanks a lot for this great PR

let oldChildren = oldParentVNode!=null && oldParentVNode!=EMPTY_OBJ && oldParentVNode._children || EMPTY_ARR;
// This is a compression of oldParentVNode!=null && oldParentVNode != EMPTY_OBJ && oldParentVNode._children || EMPTY_ARR
// as EMPTY_OBJ._children should be `undefined`.
let oldChildren = oldParentVNode!=null && oldParentVNode._children || EMPTY_ARR;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems safe to me. My guess is the original checks were a combination of before + after oldParentVNode became reliably a (vnode | null).

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So good! 🌈

@marvinhagemeister marvinhagemeister merged commit cc4b770 into preactjs:master Apr 28, 2019
@jviide jviide deleted the golf-diff branch April 28, 2019 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants