Skip to content

Commit

Permalink
Performance: use decodePos in _addLastExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
nsams committed Mar 29, 2016
1 parent 40ab85b commit 34a9ae4
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions Kwf/SourceMaps/SourceMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,37 +429,40 @@ protected function _addLastExtension()
$lineCount = 0;

$str = $this->_map->mappings;
$end = strlen($str);
$pos = 0;

while ($pos < $end) {

while (strlen($str) > 0) {
if ($str[0] === ';') {
$str = substr($str, 1);
if ($str[$pos] === ';') {
$pos++;
$previousGeneratedColumn = 0;
$lineCount++;
} else if ($str[0] === ',') {
$str = substr($str, 1);
} else if ($str[$pos] === ',') {
$pos++;
} else {
// Generated column.
$previousGeneratedColumn += Kwf_SourceMaps_Base64VLQ::decode($str);
$previousGeneratedColumn += Kwf_SourceMaps_Base64VLQ::decodePos($str, $pos);

if (strlen($str) > 0 && !($str[0] == ',' || $str[0] == ';')) {
if ($pos < $end && !($str[$pos]==',' || $str[$pos]==';')) {
// Original source.
$previousSource += Kwf_SourceMaps_Base64VLQ::decode($str);
if (strlen($str) === 0 || ($str[0] == ',' || $str[0] == ';')) {
$previousSource += Kwf_SourceMaps_Base64VLQ::decodePos($str, $pos);
if ($pos >= $end || ($str[$pos]==',' || $str[$pos]==';')) {
throw new Exception('Found a source, but no line and column');
}

// Original line.
$previousOriginalLine += Kwf_SourceMaps_Base64VLQ::decode($str);
if (strlen($str) === 0 || ($str[0] == ',' || $str[0] == ';')) {
$previousOriginalLine += Kwf_SourceMaps_Base64VLQ::decodePos($str, $pos);
if ($pos >= $end || ($str[$pos] == ',' || $str[$pos] == ';')) {
throw new Exception('Found a source and line, but no column');
}

// Original column.
$previousOriginalColumn += Kwf_SourceMaps_Base64VLQ::decode($str);
$previousOriginalColumn += Kwf_SourceMaps_Base64VLQ::decodePos($str, $pos);

if (strlen($str) > 0 && !($str[0] == ',' || $str[0] == ';')) {
if ($pos < $end && !($str[$pos] == ',' || $str[$pos] == ';')) {
// Original name.
$previousName += Kwf_SourceMaps_Base64VLQ::decode($str);
$previousName += Kwf_SourceMaps_Base64VLQ::decodePos($str, $pos);
}
}
}
Expand Down

0 comments on commit 34a9ae4

Please sign in to comment.