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

small javascript code cleanup #138

Merged
merged 2 commits into from
Mar 17, 2017
Merged

Conversation

dryganets
Copy link
Contributor

just generic cleanup

i = 0;
mycbmap = {};
mycbmap = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see why do we need to have an array here

if (result.length == 0){
return;
}
last = result.length - 1;
for (i = j = 0, ref = last; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I don't understand the reason behind such complexity.
Though I'm not a js developer so I might be missing something.

for (i = j = 0, ref = last; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {

the ref could be == -1 only in case the map is empty.
I don't think we need to handle this case there.

In all other cases, the ref is >= 0.
So 0 <= ref is always true and we never will use --j and j >= ref.

Copy link
Owner

Choose a reason for hiding this comment

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

the reason for this is that it is translated from a coffee script. I keep it in sync with Cordova plugin.

@andpor
Copy link
Owner

andpor commented Mar 15, 2017

Sergey - apologies but I won't merge this in as I want to stay as close as possible to the translated version of the coffee script.

@andpor andpor closed this Mar 15, 2017
@itinance
Copy link
Contributor

Sad. I always stumbled upon this crazy loop implementation and so I was very excited about this cleanup and that someone finally stepped thru this "special"-for-loop that i've never understood in detail, and improved it to a simple one. This PR also could have some (minor) performance-improvements since it takes a lot of complexity and ternary-operations with every iteration on the loop.

Since this code shall base always on cordova plugin (why?), which is based on coffeescript and is transpiled to javascript, there would be never any chance to get improved, simple-to-understand and simple-to-change-javascript code in this repository like happened with this PR?

I'm not sure if this is future-proof and if we can get more companies sending their improvements to this repo then

@andpor
Copy link
Owner

andpor commented Mar 16, 2017

@dryganets Sergey - I re-opened this PR - I will review again and reconsider based on performance improvement factor.

@itinance this is staying close to cordova version of the JS glue because I periodically merge the fixes from that repo. Since the fixes are usually applied to CoffeeScript there it is sometimes very hard to figure out how it applies to converted JS, if that JS is radically changed...

@andpor andpor reopened this Mar 16, 2017
@andpor andpor merged commit 4b22adf into andpor:master Mar 17, 2017
@andpor
Copy link
Owner

andpor commented Mar 17, 2017

Merged. Thank you.

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.

3 participants