Skip to content

Commit

Permalink
Optimization: do not split source string into array if there is only …
Browse files Browse the repository at this point in the history
…one class in the file
  • Loading branch information
lisachenko committed Nov 3, 2013
1 parent cdf1f76 commit cfa8237
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Go/Instrument/Transformer/WeavingTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,22 @@ private function processSingleClass(StreamMetaData $metadata, $class, &$lineOffs
$child->setParentName($newParentName);

// Add child to source
$lastLine = $class->getEndLine() + $lineOffset; // returns the last line of class
$dataArray = explode("\n", $metadata->source);
$tokenCount = $class->getBroker()->getFileTokens($class->getFileName())->count();
if ($tokenCount - $class->getEndPosition() < 3) {
// If it's the last class in a file, just add child source
$metadata->source .= $child . PHP_EOL;
} else {
$lastLine = $class->getEndLine() + $lineOffset; // returns the last line of class
$dataArray = explode("\n", $metadata->source);

$currentClassArray = array_splice($dataArray, 0, $lastLine);
$childClassArray = explode("\n", $child);
$lineOffset += count($childClassArray) + 2; // returns LoC for child class + 2 blank lines
$currentClassArray = array_splice($dataArray, 0, $lastLine);
$childClassArray = explode("\n", $child);
$lineOffset += count($childClassArray) + 2; // returns LoC for child class + 2 blank lines

$dataArray = array_merge($currentClassArray, array(''), $childClassArray, array(''), $dataArray);
$dataArray = array_merge($currentClassArray, array(''), $childClassArray, array(''), $dataArray);

$metadata->source = implode("\n", $dataArray);
$metadata->source = implode("\n", $dataArray);
}
}

/**
Expand Down

0 comments on commit cfa8237

Please sign in to comment.