Skip to content

Commit

Permalink
#124 another 2x parsing performance improvement for large files
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Jul 26, 2022
1 parent 2e59954 commit bfac7ad
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 303 deletions.
2 changes: 1 addition & 1 deletion bin/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ testName() {
#
#
cd ../test
pwd
#pwd
#
#
if [ $# -gt 0 ]; then
Expand Down
11 changes: 6 additions & 5 deletions cli/css-parser
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/bin/php
#!/usr/bin/env php
<?php

use TBela\CSS\Cli\Args;
use TBela\CSS\Cli\Exceptions\MissingParameterException;
use TBela\CSS\Parser;
use TBela\CSS\Renderer;

require __DIR__ . '/../vendor/autoload.php';

// only use from the cli
if (php_sapi_name() != 'cli') {

fwrite(STDERR, 'this program must be run from the cli');
fwrite(STDERR, 'this program must be executed from the cli');
exit(1);
}

Expand Down Expand Up @@ -69,7 +70,7 @@ try {
$cli->add('render-duplicate-declarations', 'render duplicate declarations', 'bool', 'r', multiple: false, group: 'render');
$cli->add('output', 'output file name', 'string', 'o', multiple: false, group: 'render');
$cli->add('ast', 'dump ast as JSON', 'bool', 'a', multiple: false, group: 'render');
$cli->add('format', 'ast export format', 'string', 'F', multiple: false, options: ['json', 'serialize'], dependsOn: 'ast', group: 'render');
$cli->add('output-format', 'ast export format', 'string', 'F', multiple: false, options: ['json', 'serialize'], dependsOn: 'ast', group: 'render');

$cli->parse();

Expand Down Expand Up @@ -183,7 +184,7 @@ Dual licensed under MIT or LGPL v3\n", $exe, $data['version'], date('Y'), implod

$ast = $parser->getAst();

if (($args['format'] ?? 'json') == 'serialize') {
if (($args['output-format'] ?? 'json') == 'serialize') {

$ast = serialize($ast);
}
Expand All @@ -203,7 +204,7 @@ Dual licensed under MIT or LGPL v3\n", $exe, $data['version'], date('Y'), implod

} else {

$renderer = new \TBela\CSS\Renderer($renderOptions);
$renderer = new Renderer($renderOptions);

if ($outFile == STDOUT) {

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"parser",
"minifier",
"beautifier",
"AST",
"AstTest",
"PHP"
],
"homepage": "https://github.com/tbela99/css",
Expand Down Expand Up @@ -45,5 +45,8 @@
},
"scripts": {
"test": "./bin/runtest.sh"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
}
}
278 changes: 0 additions & 278 deletions composer.lock

This file was deleted.

23 changes: 23 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
testdox="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>test</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
5 changes: 5 additions & 0 deletions src/Parser/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ protected static function doParseUrl($url)
public static function getCurrentDirectory()
{

if (php_sapi_name() == 'cli') {

return getcwd();
}

if (isset($_SERVER['PWD'])) {

// when executing via the cli
Expand Down
Loading

0 comments on commit bfac7ad

Please sign in to comment.