asika32764 / php-simple-console

Single file CLI framework to help you write build scripts.
https://packagist.org/packages/asika/simple-console
21 stars 1 forks source link

Iterations calling the count function #4

Open hansw-nlo opened 3 years ago

hansw-nlo commented 3 years ago

Hi there,

A small question. Looking at the Friendica source I see they are using your Console.php code. There is however one spot in the Console.php file where a count is being used instead of calculating the array with a predefined var.

The old code:

   protected function parseArgv($argv)
    {
        $this->executable = array_shift($argv);
        $key = null;
        $out = array();
        for ($i = 0, $j = count($argv); $i < $j; $i++) {

This is a bit faster

   protected function parseArgv($argv)
    {
        $this->executable = array_shift($argv);
        $key = null;
        $out = array();
        $num_argv = count($argv);

        for ($i = 0, $j = $num_argv; $i < $j; $i++) {

Would you be willing to change this in the project code so we can use a new version of it? It prevents calling the count function for each iteration.

Thanks,

Hans

asika32764 commented 3 years ago

I can do this change but I don't have time to test it.

If you can create a PR, I will very grateful.

hansw-nlo commented 3 years ago

Hi Asika,

Sorry to hear that, it means adding one line, altering a different one. I added the code in my initial posting but here is the complete file. I only altered the suggested ones. You can simply rename it and upload it.

Console.txt

hansw-nlo commented 3 years ago

I have tested it myself on my own Friendica instance. If that is enough for you then I suppose you can update it.