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

Convert intval to typecast int #491

Closed
DiogoParrinha opened this issue May 7, 2014 · 29 comments
Closed

Convert intval to typecast int #491

DiogoParrinha opened this issue May 7, 2014 · 29 comments
Labels
b:1.8 Branch: 1.8.x s:resolved Status: Resolved. Solution implemented or scheduled t:enhancement Type: Enhancement. Contains minor improvements
Milestone

Comments

@DiogoParrinha
Copy link
Contributor

Speed Tests Reference:
http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/

The speed increase is incredible and since we have a lot of intval's, I decided to write a script to help me out.

PHP Script:
http://pastebin.com/Qjfk1WEh

Usage: intval.php?dir=[PATH]

@DiogoParrinha DiogoParrinha added this to the 1.8 Beta 1 milestone May 7, 2014
@DiogoParrinha DiogoParrinha self-assigned this May 7, 2014
@darksonic37
Copy link

Does the speed increase apply to strval($foo) vs (string)$foo as well?

strval() occurs in captcha.php. Even if it's not faster, typecasting should still be preferred for some consistency.

Actually, is strval() even needed there?

@darksonic37
Copy link

There is also a bunch of occurrences for floatval().

@DiogoParrinha
Copy link
Contributor Author

We need to do the replacement for floatval too but the amount of occurrences is much lower. As for the captcha, shouldn't be needed to replace by anything.

@darksonic37
Copy link

There is a strval() in captcha.php. Why not typecast there instead? It's a tiny detail but... :P

@JordanMussi
Copy link
Contributor

For consistency, yes it should be changed to a typecast. 👅

@DiogoParrinha
Copy link
Contributor Author

I just think that we should focus on important things rather than tiny details right now, but I guess that's just me.

@JN-Jones
Copy link
Contributor

JN-Jones commented May 9, 2014

Not only ;) we can change this in a few seconds before we release beta 1, 2 or even before the final release - we should finish the jQuery conversion and release beta 1 ASAP

@darksonic37
Copy link

I was just pointing it out. I didn't see this mentioned before.

On Fri, May 9, 2014 at 8:16 PM, Jones notifications@github.com wrote:

Not only ;) we can change this in a few seconds before we release beta 1, 2 or even before the final release - we should finish the jQuery conversion and release beta 1 ASAP

Reply to this email directly or view it on GitHub:
#491 (comment)

@Sama34
Copy link
Contributor

Sama34 commented May 11, 2014

We can push this on Beta 1 and leave the rest of possible type-casting for beta 2. Who is the one to apply this? IIRC there were no issues on the tests done.

@DiogoParrinha
Copy link
Contributor Author

I can do this, not a problem. But I'll only be able to look at this Thursday - though I believe there's no rush. We still have jQuery to complete.

@Stefan-MyBB
Copy link
Contributor

Do it as late as possible, it may break pull requests and other stuff.

@DiogoParrinha
Copy link
Contributor Author

Stefan is right, we should do this only when we're about to release Beta 1.

@PenguinPaul
Copy link
Contributor

Looks like Beta 2 then?

@JordanMussi
Copy link
Contributor

Yeah 👅 looks like we forgot this one...

@DiogoParrinha
Copy link
Contributor Author

I didn't forget it - we can't risk losing PR compatibility until a few days before Beta 2 is ready. I postponed it to Beta 2.

@WildcardSearch
Copy link
Contributor

I am of the opinion that this should be one of the last changes made before final testing. As mentioned it will effect almost every active PR so it would be best to finish all open issues (are as many as are feasible) before making this change.

@DiogoParrinha DiogoParrinha modified the milestones: 1.8 Beta 3, 1.8 Beta 2 Jun 24, 2014
@DiogoParrinha
Copy link
Contributor Author

Postponing to Beta 3.

@Sama34
Copy link
Contributor

Sama34 commented Jul 17, 2014

@PirataNervo remember this is to be pushed at the last moment, we should get all enhancements and PRs done by then.

@DiogoParrinha
Copy link
Contributor Author

@Sama34 yeap I remember :)

DiogoParrinha pushed a commit that referenced this issue Jul 21, 2014
@DiogoParrinha
Copy link
Contributor Author

This is finished.

@JordanMussi
Copy link
Contributor

Before: $pms = implode(",", array_map("intval", $pms));
After: $pms = implode(",", array_map("(int), $pms); - missing " and you can't array_map using a cast either...
Should be (how it started): $pms = implode(",", array_map("intval", $pms);
https://github.com/mybb/mybb/blob/feature/moderation.php#L2791

We need to find more occurrences of this... (if there are any)

@JordanMussi JordanMussi reopened this Jul 21, 2014
@euantorano
Copy link
Member

Nice catch Jordan!

@JordanMussi
Copy link
Contributor

Right, there are more locations.

Here's the list of all of them...


Some array_map('intval')s are unaffected. It must have been an odd issue in the converter...

@DiogoParrinha
Copy link
Contributor Author

Yes the converted skipped array_maps. But I'll fix those manually now. Thanks Jordan.
EDIT: Ah the converted looked for ' and not " in array_map. It should have looked for both.

@DiogoParrinha
Copy link
Contributor Author

@JordanMussi I think some of those locations are not right. I guess you probably just searched array_map rather than array_map("(int)

I've fixed 16 occurrences, going to commit now.

@DiogoParrinha
Copy link
Contributor Author

I think this can be closed now.

@Starpaul20
Copy link
Member

There are still some PHP parse errors. The array_map functions in 12096ed are all missing a closing parentheses ( ) ).

@DiogoParrinha
Copy link
Contributor Author

Oops, forgot the converter did that too. Fixed that and the (int)(int) found in one file.

@DiogoParrinha
Copy link
Contributor Author

I've gone through many many pages and didn't find any parse errors related to this, so I'm closing this issue.

@DiogoParrinha DiogoParrinha removed their assignment Jan 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b:1.8 Branch: 1.8.x s:resolved Status: Resolved. Solution implemented or scheduled t:enhancement Type: Enhancement. Contains minor improvements
Projects
None yet
Development

No branches or pull requests

10 participants