Skip to content
Derek Jones edited this page Jul 4, 2012 · 11 revisions

Category:Core::Optimize This page will keep track of all Regex improvements. Once the code improvement has been added, it will be marked as Added. If you get a chance, go through as many approvements as possible and approve it or don't approve it. Keep in mind CodeIgniter's goals (meaning don't write improvements that won't work everywhere). If a code improvement gets a lot of "Not Approved", it will probably be dropped from this page.

DO NOT EDIT SUBMITTED CODE. IF YOU THINK OF A BETTER IMPROVEMENT, MARK THE CURRENT CODE AS "NOT APPROVED" AND SUBMIT YOUR OWN.


[b][color=red]NOT ADDED[/color][/b] [b]system/helpers/string_helper.php - line 70[/b]


[b][color=green]SUGGESTED BY:[/color][/b] Geert De Deckere


[b][color=green]APPROVED BY:[/color][/b]


[b][color=red]NOT APPROVED BY:[/color][/b]


[b][color=red]BEFORE:[/color][/b] 10000 iterations take about [b]0.0873 seconds[/b]

function reduce_double_slashes($str)
{
 return preg_replace("#([^:])//+#", "\\1/", $str);
}

[b][color=green]AFTER:[/color][/b] 10000 iterations take about [b]0.0429 seconds[/b]

function reduce_double_slashes($str)
{
 return preg_replace('#(?<!:)//+#', '/', $str); // twice as fast, woot!
}

[b]Just copy and paste the template below to add your own addition.[/b]


[b][color=red]NOT ADDED[/color][/b] [b]system/REPLACE/REPLACE.php - line ??[/b]


[b][color=green]SUGGESTED BY:[/color][/b]


[b][color=green]APPROVED BY:[/color][/b]


[b][color=red]NOT APPROVED BY:[/color][/b]


[b][color=red]BEFORE:[/color][/b]

//put the original code here

[b][color=green]AFTER:[/color][/b]

//put the replaced code here

Clone this wiki locally