Skip to content

Commit

Permalink
Optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 9, 2019
1 parent fc5dbcc commit 94eea79
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Exporter/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace drupol\phptree\Exporter;

use drupol\phptree\Node\NodeInterface;
use drupol\phptree\Traverser\BreadthFirst;
use drupol\phptree\Traverser\PreOrder;
use drupol\phptree\Traverser\TraverserInterface;
use Fhaculty\Graph\Graph as OriginalGraph;
use Fhaculty\Graph\Vertex;
Expand Down Expand Up @@ -38,7 +38,7 @@ class Graph implements ExporterInterface
public function __construct(OriginalGraph $graph = null, TraverserInterface $traverser = null)
{
$this->graph = $graph ?? new OriginalGraph();
$this->traverser = $traverser ?? new BreadthFirst();
$this->traverser = $traverser ?? new PreOrder();
}

/**
Expand Down
10 changes: 3 additions & 7 deletions src/Modifier/Reverse.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ public function modify(NodeInterface $tree): NodeInterface
$children->append($this->modify($child));
}

$newTree = $tree->withChildren();

for ($i = $children->count()-1; $i >= 0; $i--) {
$newTree->add($children[$i]);
}

return $newTree;
return $tree->withChildren(...\array_reverse(
$children->getArrayCopy()
));
}
}

0 comments on commit 94eea79

Please sign in to comment.