Skip to content

Commit 3b8ff9b

Browse files
authored
Merge pull request #66 from stof/function_invocation_optimization
Use fully-qualified calls for compiler optimized functions
2 parents 6fa9789 + 75928b9 commit 3b8ff9b

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/Seld/JsonLint/JsonParser.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function parse($input, $flags = 0)
173173

174174
while (true) {
175175
// retrieve state number from top of stack
176-
$state = $this->stack[count($this->stack)-1];
176+
$state = $this->stack[\count($this->stack)-1];
177177

178178
// use default actions if available
179179
if (isset($this->defaultActions[$state])) {
@@ -198,7 +198,7 @@ public function parse($input, $flags = 0)
198198
}
199199

200200
$message = null;
201-
if (in_array("'STRING'", $expected) && in_array(substr($this->lexer->match, 0, 1), array('"', "'"))) {
201+
if (\in_array("'STRING'", $expected) && \in_array(substr($this->lexer->match, 0, 1), array('"', "'"))) {
202202
$message = "Invalid string";
203203
if ("'" === substr($this->lexer->match, 0, 1)) {
204204
$message .= ", it appears you used single quotes instead of double quotes";
@@ -214,7 +214,7 @@ public function parse($input, $flags = 0)
214214
if ($message) {
215215
$errStr .= $message;
216216
} else {
217-
$errStr .= (count($expected) > 1) ? "Expected one of: " : "Expected: ";
217+
$errStr .= (\count($expected) > 1) ? "Expected one of: " : "Expected: ";
218218
$errStr .= implode(', ', $expected);
219219
}
220220

@@ -248,25 +248,25 @@ public function parse($input, $flags = 0)
248248
// try to recover from error
249249
while (true) {
250250
// check for error recovery rule in this state
251-
if (array_key_exists($TERROR, $this->table[$state])) {
251+
if (\array_key_exists($TERROR, $this->table[$state])) {
252252
break;
253253
}
254254
if ($state == 0) {
255255
throw new ParsingException($errStr ?: 'Parsing halted.');
256256
}
257257
$this->popStack(1);
258-
$state = $this->stack[count($this->stack)-1];
258+
$state = $this->stack[\count($this->stack)-1];
259259
}
260260

261261
$preErrorSymbol = $symbol; // save the lookahead token
262262
$symbol = $TERROR; // insert generic error symbol as new lookahead
263-
$state = $this->stack[count($this->stack)-1];
263+
$state = $this->stack[\count($this->stack)-1];
264264
$action = isset($this->table[$state][$TERROR]) ? $this->table[$state][$TERROR] : false;
265265
$recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
266266
}
267267

268268
// this shouldn't happen, unless resolve defaults are off
269-
if (is_array($action[0]) && count($action) > 1) {
269+
if (\is_array($action[0]) && \count($action) > 1) {
270270
throw new ParsingException('Parse Error: multiple actions possible at state: ' . $state . ', token: ' . $symbol);
271271
}
272272

@@ -295,13 +295,13 @@ public function parse($input, $flags = 0)
295295
$len = $this->productions_[$action[1]][1];
296296

297297
// perform semantic action
298-
$yyval->token = $this->vstack[count($this->vstack) - $len]; // default to $$ = $1
298+
$yyval->token = $this->vstack[\count($this->vstack) - $len]; // default to $$ = $1
299299
// default location, uses first token for firsts, last for lasts
300300
$yyval->store = array( // _$ = store
301-
'first_line' => $this->lstack[count($this->lstack) - ($len ?: 1)]['first_line'],
302-
'last_line' => $this->lstack[count($this->lstack) - 1]['last_line'],
303-
'first_column' => $this->lstack[count($this->lstack) - ($len ?: 1)]['first_column'],
304-
'last_column' => $this->lstack[count($this->lstack) - 1]['last_column'],
301+
'first_line' => $this->lstack[\count($this->lstack) - ($len ?: 1)]['first_line'],
302+
'last_line' => $this->lstack[\count($this->lstack) - 1]['last_line'],
303+
'first_column' => $this->lstack[\count($this->lstack) - ($len ?: 1)]['first_column'],
304+
'last_column' => $this->lstack[\count($this->lstack) - 1]['last_column'],
305305
);
306306
$r = $this->performAction($yyval, $yytext, $yyleng, $yylineno, $action[1], $this->vstack, $this->lstack);
307307

@@ -316,7 +316,7 @@ public function parse($input, $flags = 0)
316316
$this->stack[] = $this->productions_[$action[1]][0]; // push nonterminal (reduce)
317317
$this->vstack[] = $yyval->token;
318318
$this->lstack[] = $yyval->store;
319-
$newState = $this->table[$this->stack[count($this->stack)-2]][$this->stack[count($this->stack)-1]];
319+
$newState = $this->table[$this->stack[\count($this->stack)-2]][$this->stack[\count($this->stack)-1]];
320320
$this->stack[] = $newState;
321321
break;
322322

@@ -340,17 +340,17 @@ protected function parseError($str, $hash)
340340
private function performAction(stdClass $yyval, $yytext, $yyleng, $yylineno, $yystate, &$tokens)
341341
{
342342
// $0 = $len
343-
$len = count($tokens) - 1;
343+
$len = \count($tokens) - 1;
344344
switch ($yystate) {
345345
case 1:
346346
$yytext = preg_replace_callback('{(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})}', array($this, 'stringInterpolation'), $yytext);
347347
$yyval->token = $yytext;
348348
break;
349349
case 2:
350350
if (strpos($yytext, 'e') !== false || strpos($yytext, 'E') !== false) {
351-
$yyval->token = floatval($yytext);
351+
$yyval->token = \floatval($yytext);
352352
} else {
353-
$yyval->token = strpos($yytext, '.') === false ? intval($yytext) : floatval($yytext);
353+
$yyval->token = strpos($yytext, '.') === false ? \intval($yytext) : \floatval($yytext);
354354
}
355355
break;
356356
case 3:
@@ -456,9 +456,9 @@ private function stringInterpolation($match)
456456
case '\"':
457457
return '"';
458458
case '\b':
459-
return chr(8);
459+
return \chr(8);
460460
case '\f':
461-
return chr(12);
461+
return \chr(12);
462462
case '\n':
463463
return "\n";
464464
case '\r':
@@ -474,9 +474,9 @@ private function stringInterpolation($match)
474474

475475
private function popStack($n)
476476
{
477-
$this->stack = array_slice($this->stack, 0, - (2 * $n));
478-
$this->vstack = array_slice($this->vstack, 0, - $n);
479-
$this->lstack = array_slice($this->lstack, 0, - $n);
477+
$this->stack = \array_slice($this->stack, 0, - (2 * $n));
478+
$this->vstack = \array_slice($this->vstack, 0, - $n);
479+
$this->lstack = \array_slice($this->lstack, 0, - $n);
480480
}
481481

482482
private function lex()

src/Seld/JsonLint/Lexer.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,26 @@ public function setInput($input)
8181
public function showPosition()
8282
{
8383
$pre = str_replace("\n", '', $this->getPastInput());
84-
$c = str_repeat('-', max(0, strlen($pre) - 1)); // new Array(pre.length + 1).join("-");
84+
$c = str_repeat('-', max(0, \strlen($pre) - 1)); // new Array(pre.length + 1).join("-");
8585

8686
return $pre . str_replace("\n", '', $this->getUpcomingInput()) . "\n" . $c . "^";
8787
}
8888

8989
public function getPastInput()
9090
{
91-
$past = substr($this->matched, 0, strlen($this->matched) - strlen($this->match));
91+
$past = substr($this->matched, 0, \strlen($this->matched) - \strlen($this->match));
9292

93-
return (strlen($past) > 20 ? '...' : '') . substr($past, -20);
93+
return (\strlen($past) > 20 ? '...' : '') . substr($past, -20);
9494
}
9595

9696
public function getUpcomingInput()
9797
{
9898
$next = $this->match;
99-
if (strlen($next) < 20) {
100-
$next .= substr($this->input, 0, 20 - strlen($next));
99+
if (\strlen($next) < 20) {
100+
$next .= substr($this->input, 0, 20 - \strlen($next));
101101
}
102102

103-
return substr($next, 0, 20) . (strlen($next) > 20 ? '...' : '');
103+
return substr($next, 0, 20) . (\strlen($next) > 20 ? '...' : '');
104104
}
105105

106106
protected function parseError($str, $hash)
@@ -128,29 +128,29 @@ private function next()
128128
}
129129

130130
$rules = $this->getCurrentRules();
131-
$rulesLen = count($rules);
131+
$rulesLen = \count($rules);
132132

133133
for ($i=0; $i < $rulesLen; $i++) {
134134
if (preg_match($this->rules[$rules[$i]], $this->input, $match)) {
135135
preg_match_all('/\n.*/', $match[0], $lines);
136136
$lines = $lines[0];
137137
if ($lines) {
138-
$this->yylineno += count($lines);
138+
$this->yylineno += \count($lines);
139139
}
140140

141141
$this->yylloc = array(
142142
'first_line' => $this->yylloc['last_line'],
143143
'last_line' => $this->yylineno+1,
144144
'first_column' => $this->yylloc['last_column'],
145-
'last_column' => $lines ? strlen($lines[count($lines) - 1]) - 1 : $this->yylloc['last_column'] + strlen($match[0]),
145+
'last_column' => $lines ? \strlen($lines[\count($lines) - 1]) - 1 : $this->yylloc['last_column'] + \strlen($match[0]),
146146
);
147147
$this->yytext .= $match[0];
148148
$this->match .= $match[0];
149-
$this->yyleng = strlen($this->yytext);
149+
$this->yyleng = \strlen($this->yytext);
150150
$this->more = false;
151-
$this->input = substr($this->input, strlen($match[0]));
151+
$this->input = substr($this->input, \strlen($match[0]));
152152
$this->matched .= $match[0];
153-
$token = $this->performAction($rules[$i], $this->conditionStack[count($this->conditionStack)-1]);
153+
$token = $this->performAction($rules[$i], $this->conditionStack[\count($this->conditionStack)-1]);
154154
if ($token) {
155155
return $token;
156156
}
@@ -175,7 +175,7 @@ private function next()
175175

176176
private function getCurrentRules()
177177
{
178-
return $this->conditions[$this->conditionStack[count($this->conditionStack)-1]]['rules'];
178+
return $this->conditions[$this->conditionStack[\count($this->conditionStack)-1]]['rules'];
179179
}
180180

181181
private function performAction($avoiding_name_collisions, $YY_START)

0 commit comments

Comments
 (0)