Skip to content

Commit

Permalink
added \ before some PHP functions to improve speed slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
k00ni committed Jun 21, 2018
1 parent 51a1530 commit 5ee46fb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion ARC2_Class.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ function backupStoreData($store, $target_path, $offset = 0) {
' . ($offset ? 'OFFSET ' . $offset : '') . '
';
$rows = $store->query($q, 'rows');
$tc = count($rows);
$tc = \count($rows);
$full_tc = $tc + $offset;
$mode = $offset ? 'ab' : 'wb';
$fp = fopen($target_path, $mode);
Expand Down
14 changes: 7 additions & 7 deletions store/ARC2_Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ public function removeQueueTicket($t)
$this->db->simpleQuery('LOCK TABLES '.$this->getTablePrefix().'setting WRITE');
/* queue */
$vals = $this->getSetting('query_queue', []);
$pos = array_search($t, $vals);
$queue = ($pos < (count($vals) - 1)) ? array_slice($vals, $pos + 1) : [];
$pos = \array_search($t, $vals);
$queue = ($pos < (count($vals) - 1)) ? \array_slice($vals, $pos + 1) : [];
$this->setSetting('query_queue', $queue);
$this->db->simpleQuery('UNLOCK TABLES');
}
Expand Down Expand Up @@ -477,7 +477,7 @@ public function renameTo($name)

public function replicateTo($name)
{
$conf = array_merge($this->a, ['store_name' => $name]);
$conf = \array_merge($this->a, ['store_name' => $name]);
$new_store = ARC2::getStore($conf);
$new_store->setUp();
$new_store->reset();
Expand Down Expand Up @@ -540,7 +540,7 @@ public function query($q, $result_format = '', $src = '', $keep_bnode_ids = 0, $

$infos['result_format'] = $result_format;

if (!isset($p) || 0 == count($errors)) {
if (!isset($p) || 0 == \count($errors)) {
$qt = $infos['query']['type'];
if (!in_array($qt, ['select', 'ask', 'describe', 'construct', 'load', 'insert', 'delete', 'dump'])) {
return $this->addError('Unsupported query type "'.$qt.'"');
Expand Down Expand Up @@ -628,7 +628,7 @@ public function processTriggers($type, $infos)
$trigger .= !preg_match('/Trigger$/', $trigger) ? 'Trigger' : '';
if (ARC2::inc(ucfirst($trigger), $trigger_inc_path)) {
$cls = 'ARC2_'.ucfirst($trigger);
$config = array_merge($this->a, ['query_infos' => $infos]);
$config = \array_merge($this->a, ['query_infos' => $infos]);
$trigger_obj = new $cls($config, $this);
if (method_exists($trigger_obj, 'go')) {
$r['trigger_results'][] = $trigger_obj->go();
Expand Down Expand Up @@ -673,7 +673,7 @@ public function getTermID($val, $term = '')
$rows = $this->db->fetchList(
'SELECT id, val FROM '.$this->getTablePrefix().$tbl." WHERE val_hash = '".$this->getValueHash($val)."' ORDER BY id"
);
if (is_array($rows) && 0 < count($rows)) {
if (is_array($rows) && 0 < \count($rows)) {
foreach($rows as $row) {
if ($row['val'] == $val) {
$r = $row['id'];
Expand Down Expand Up @@ -842,7 +842,7 @@ public function getResourceLabel($res, $unnamed_label = 'An unnamed resource')

public function getLabelProps()
{
return array_merge(
return \array_merge(
$this->v('rdf_label_properties', [], $this->a),
[
'http://www.w3.org/2000/01/rdf-schema#label',
Expand Down
4 changes: 2 additions & 2 deletions store/ARC2_StoreDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ public function getSafeValue($val)
'%1A' => ',',
'%1F' => '',
];
$froms = array_keys($mappings);
$tos = array_values($mappings);
$froms = \array_keys($mappings);
$tos = \array_values($mappings);
foreach ($froms as $i => $from) {
$froms[$i] = urldecode($from);
}
Expand Down
44 changes: 22 additions & 22 deletions store/ARC2_StoreSelectQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getSQL()
$nl = "\n";
$this->buildInitialIndexes();
foreach ($this->indexes as $i => $index) {
$this->index = array_merge($this->getEmptyIndex(), $index);
$this->index = \array_merge($this->getEmptyIndex(), $index);
$this->analyzeIndex($this->getPattern('0'));
$sub_r = $this->getQuerySQL();
$r .= $r ? $nl.'UNION'.$this->getDistinctSQL().$nl : '';
Expand Down Expand Up @@ -214,7 +214,7 @@ public function getFinalQueryResult($q_sql, $tmp_tbl)
$t2 = ARC2::mtime();
$rows = [];
$types = [0 => 'uri', 1 => 'bnode', 2 => 'literal'];
if (0 < count($entries)) {
if (0 < \count($entries)) {
foreach($entries as $pre_row) {
$row = [];
foreach ($vars as $var) {
Expand Down Expand Up @@ -258,8 +258,8 @@ public function buildIndex($pattern, $id)
$pattern['constraint'] = $sub_id;
} else {
$sub_patterns = $this->v('patterns', [], $pattern);
$keys = array_keys($sub_patterns);
$spc = count($sub_patterns);
$keys = \array_keys($sub_patterns);
$spc = \count($sub_patterns);
if (($spc > 4) && $this->pattern_order_offset) {
$keys = [];
for ($i = 0; $i < $spc; ++$i) {
Expand Down Expand Up @@ -297,11 +297,11 @@ public function analyzeIndex($pattern)
foreach (['s', 'p', 'o'] as $term) {
if ('var' == $pattern[$term.'_type']) {
$val = $pattern[$term];
$this->index['vars'][$val] = array_merge($this->v($val, [], $this->index['vars']), [['table' => $pattern['id'], 'col' => $term]]);
$this->index['vars'][$val] = \array_merge($this->v($val, [], $this->index['vars']), [['table' => $pattern['id'], 'col' => $term]]);
}
if ('bnode' == $pattern[$term.'_type']) {
$val = $pattern[$term];
$this->index['bnodes'][$val] = array_merge($this->v($val, [], $this->index['bnodes']), [['table' => $pattern['id'], 'col' => $term]]);
$this->index['bnodes'][$val] = \array_merge($this->v($val, [], $this->index['bnodes']), [['table' => $pattern['id'], 'col' => $term]]);
}
}
$this->index['triple_patterns'][] = $pattern['id'];
Expand All @@ -321,10 +321,10 @@ public function analyzeIndex($pattern)
if ('graph' == $info['type']) {
if ($info['var']) {
$val = $info['var']['value'];
$this->index['graph_vars'][$val] = array_merge($this->v($val, [], $this->index['graph_vars']), [['table' => $id]]);
$this->index['graph_vars'][$val] = \array_merge($this->v($val, [], $this->index['graph_vars']), [['table' => $id]]);
} elseif ($info['uri']) {
$val = $info['uri'];
$this->index['graph_uris'][$val] = array_merge($this->v($val, [], $this->index['graph_uris']), [['table' => $id]]);
$this->index['graph_uris'][$val] = \array_merge($this->v($val, [], $this->index['graph_uris']), [['table' => $id]]);
}
}
}
Expand All @@ -347,16 +347,16 @@ public function getGraphInfos($id)
}
$p_pattern = $this->index['patterns'][$pattern['parent_id']];
if (isset($p_pattern['graph_infos'])) {
return array_merge($p_pattern['graph_infos'], $r);
return \array_merge($p_pattern['graph_infos'], $r);
}

return array_merge($this->getGraphInfos($pattern['parent_id']), $r);
return \array_merge($this->getGraphInfos($pattern['parent_id']), $r);
}
/* FROM / FROM NAMED */
else {
if (isset($this->infos['query']['dataset'])) {
foreach ($this->infos['query']['dataset'] as $set) {
$r[] = array_merge(['type' => 'dataset'], $set);
$r[] = \array_merge(['type' => 'dataset'], $set);
}
}
}
Expand Down Expand Up @@ -385,7 +385,7 @@ public function getUnionIndexes($pre_index)
$min_depth = 1000;
/* only process branches with minimum depth */
foreach ($pre_index['union_branches'] as $id) {
$branches[$id] = count(preg_split('/\_/', $id));
$branches[$id] = \count(preg_split('/\_/', $id));
$min_depth = min($min_depth, $branches[$id]);
}
foreach ($branches as $branch_id => $depth) {
Expand All @@ -407,7 +407,7 @@ public function getUnionIndexes($pre_index)
}
}
if ($index['union_branches']) {
$r = array_merge($r, $this->getUnionIndexes($index));
$r = \array_merge($r, $this->getUnionIndexes($index));
} else {
$r[] = $index;
}
Expand Down Expand Up @@ -619,7 +619,7 @@ public function getFROMSQL()

public function getOrderedJoinIDs()
{
return array_merge($this->index['from'], $this->index['join'], $this->index['left_join']);
return \array_merge($this->index['from'], $this->index['join'], $this->index['left_join']);
}

public function getJoinInfos($id)
Expand Down Expand Up @@ -651,7 +651,7 @@ public function getAllJoinsSQL()
{
$js = $this->getJoins();
$ljs = $this->getLeftJoins();
$entries = array_merge($js, $ljs);
$entries = \array_merge($js, $ljs);
$id2code = [];
foreach ($entries as $entry) {
if (preg_match('/([^\s]+) ON (.*)/s', $entry, $m)) {
Expand Down Expand Up @@ -744,7 +744,7 @@ public function getJoinConditionSQL($id)
$d_tbls = $this->getDependentJoins($id);
foreach ($d_tbls as $d_tbl) {
if (preg_match('/^T_([0-9\_]+)\.[spo]+/', $d_tbl, $m) && ($m[1] != $id)) {
if ($this->isJoinedBefore($m[1], $id) && !in_array($m[1], array_merge($this->index['from'], $this->index['join']))) {
if ($this->isJoinedBefore($m[1], $id) && !in_array($m[1], \array_merge($this->index['from'], $this->index['join']))) {
$r .= $r ? $nl.' AND ' : $nl.' ';
$r .= '('.$d_tbl.' IS NOT NULL)';
}
Expand Down Expand Up @@ -787,7 +787,7 @@ public function problematicDependencies()
{
foreach ($this->dependency_log as $id => $tbls) {
if (count($tbls) > 1) {
return count($tbls);
return \count($tbls);
}
}

Expand All @@ -809,7 +809,7 @@ public function isJoinedBefore($tbl_1, $tbl_2)

public function joinDependsOn($id, $id2)
{
if (in_array($id2, array_merge($this->index['from'], $this->index['join']))) {
if (in_array($id2, \array_merge($this->index['from'], $this->index['join']))) {
return 1;
}
$d_tbls = $this->getDependentJoins($id2);
Expand Down Expand Up @@ -1678,7 +1678,7 @@ public function getLangCallSQL($pattern, $context)

public function getLangmatchesCallSQL($pattern, $context)
{
if (2 == count($pattern['args'])) {
if (2 == \count($pattern['args'])) {
$arg_1 = $pattern['args'][0];
$arg_2 = $pattern['args'][1];
$sub_r_1 = $this->getBuiltInCallSQL($arg_1, $context); /* adds value join */
Expand All @@ -1705,7 +1705,7 @@ public function getLangmatchesCallSQL($pattern, $context)
*/
public function getSametermCallSQL($pattern, $context)
{
if (2 == count($pattern['args'])) {
if (2 == \count($pattern['args'])) {
$arg_1 = $pattern['args'][0];
$arg_2 = $pattern['args'][1];
$sub_r_1 = $this->getExpressionSQL($arg_1, 'sameterm');
Expand All @@ -1721,7 +1721,7 @@ public function getSametermCallSQL($pattern, $context)

public function getRegexCallSQL($pattern, $context)
{
$ac = count($pattern['args']);
$ac = \count($pattern['args']);
if ($ac >= 2) {
foreach ($pattern['args'] as $i => $arg) {
$var = 'sub_r_'.($i + 1);
Expand Down Expand Up @@ -1853,7 +1853,7 @@ public function getValueSQL($q_tbl, $q_sql)
if ($var['aggregate']) {
$r .= 'TMP.`'.$var['alias'].'`';
} else {
$join_type = in_array($tbl, array_merge($this->index['from'], $this->index['join'])) ? 'JOIN' : 'LEFT JOIN'; /* val may be NULL */
$join_type = in_array($tbl, \array_merge($this->index['from'], $this->index['join'])) ? 'JOIN' : 'LEFT JOIN'; /* val may be NULL */
$v_tbls[$join_type][] = ['t_col' => $col, 'q_col' => $var_name, 'vc' => $vc];
$r .= 'V'.$vc.'.val AS `'.$var_name.'`';
if (in_array($col, ['s', 'o'])) {
Expand Down
18 changes: 9 additions & 9 deletions store/ARC2_StoreTableManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function createTripleTable($suffix = 'triple')
{
/* keep in sync with merge def in StoreQueryHandler ! */
$indexes = $this->v('store_indexes', ['sp (s,p)', 'os (o,s)', 'po (p,o)'], $this->a);
$index_code = $indexes ? 'KEY '.implode(', KEY ', $indexes).', ' : '';
$index_code = $indexes ? 'KEY '.\implode(', KEY ', $indexes).', ' : '';
$sql = '
CREATE TABLE IF NOT EXISTS '.$this->getTablePrefix().$suffix.' (
t INT(10) UNSIGNED NOT NULL,
Expand Down Expand Up @@ -175,7 +175,7 @@ public function createO2ValTable()
/* object value index, e.g. "KEY v (val(64))" and/or "FULLTEXT KEY vft (val)" */
$val_index = $this->v('store_object_index', 'KEY v (val(64))', $this->a);
if ($val_index) {
$val_index = ', '.ltrim($val_index, ',');
$val_index = ', '.\ltrim($val_index, ',');
}
$sql = '
CREATE TABLE IF NOT EXISTS '.$this->getTablePrefix().'o2val (
Expand Down Expand Up @@ -218,8 +218,8 @@ public function extendColumns()
$tbl_prefix = $this->getTablePrefix();
$tbls = $this->getTables();
foreach ($tbls as $suffix) {
if (preg_match('/^(triple|g2t|id2val|s2val|o2val)/', $suffix, $m)) {
$mthd = 'extend'.ucfirst($m[1]).'TableColumns';
if (\preg_match('/^(triple|g2t|id2val|s2val|o2val)/', $suffix, $m)) {
$mthd = 'extend'.\ucfirst($m[1]).'TableColumns';
$this->$mthd($suffix);
}
}
Expand All @@ -229,8 +229,8 @@ public function splitTables()
{
$old_ps = $this->getSetting('split_predicates', []);
$new_ps = $this->retrieveSplitPredicates();
$add_ps = array_diff($new_ps, $old_ps);
$del_ps = array_diff($old_ps, $new_ps);
$add_ps = \array_diff($new_ps, $old_ps);
$del_ps = \array_diff($old_ps, $new_ps);
$final_ps = [];
foreach ($del_ps as $p) {
if (!$this->unsplitPredicate($p)) {
Expand All @@ -247,7 +247,7 @@ public function splitTables()

public function unsplitPredicate($p)
{
$suffix = 'triple_'.abs(crc32($p));
$suffix = 'triple_'.\abs(\crc32($p));
$old_tbl = $this->getTablePrefix().$suffix;
$new_tbl = $this->getTablePrefix().'triple';
$p_id = $this->getTermID($p, 'p');
Expand All @@ -266,7 +266,7 @@ public function unsplitPredicate($p)

public function splitPredicate($p)
{
$suffix = 'triple_'.abs(crc32($p));
$suffix = 'triple_'.\abs(\crc32($p));
$this->createTripleTable($suffix);
$old_tbl = $this->getTablePrefix().'triple';
$new_tbl = $this->getTablePrefix().$suffix;
Expand All @@ -289,7 +289,7 @@ public function splitPredicate($p)
public function retrieveSplitPredicates()
{
$r = $this->split_predicates;
$limit = $this->max_split_tables - count($r);
$limit = $this->max_split_tables - \count($r);
$q = 'SELECT ?p COUNT(?p) AS ?pc WHERE { ?s ?p ?o } GROUP BY ?p ORDER BY DESC(?pc) LIMIT '.$limit;
$rows = $this->query($q, 'rows');
foreach ($rows as $row) {
Expand Down
20 changes: 10 additions & 10 deletions tests/db_adapter_depended/store/ARC2_StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,18 +514,18 @@ public function testGetIDValueNoData()
public function testInsertSaftRegressionTest1()
{
$res = $this->fixture->query('SELECT * FROM <http://example.com/> WHERE { ?s ?p ?o. } ');
$this->assertEquals(0, count($res['result']['rows']));
$this->assertEquals(0, \count($res['result']['rows']));

$this->fixture->insert(
file_get_contents(__DIR__.'/../../data/nt/saft-arc2-addition-regression1.nt'),
'http://example.com/'
);

$res1 = $this->fixture->query('SELECT * FROM <http://example.com/> WHERE { ?s ?p ?o. } ');
$this->assertEquals(442, count($res1['result']['rows']));
$this->assertEquals(442, \count($res1['result']['rows']));

$res2 = $this->fixture->query('SELECT * WHERE { ?s ?p ?o. } ');
$this->assertEquals(442, count($res2['result']['rows']));
$this->assertEquals(442, \count($res2['result']['rows']));
}

/**
Expand All @@ -540,13 +540,13 @@ public function testInsertSaftRegressionTest2()
$res = $this->fixture->query('INSERT INTO <http://localhost/Saft/TestGraph/> {<http://foo/1> <http://foo/2> <http://foo/3> . }');

$res1 = $this->fixture->query('SELECT * FROM <http://localhost/Saft/TestGraph/> WHERE {?s ?p ?o.}');
$this->assertEquals(1, count($res1['result']['rows']));
$this->assertEquals(1, \count($res1['result']['rows']));

$res2 = $this->fixture->query('SELECT * WHERE {?s ?p ?o.}');
$this->assertEquals(1, count($res2['result']['rows']));
$this->assertEquals(1, \count($res2['result']['rows']));

$res2 = $this->fixture->query('SELECT ?s ?p ?o WHERE {?s ?p ?o.}');
$this->assertEquals(1, count($res2['result']['rows']));
$this->assertEquals(1, \count($res2['result']['rows']));
}

/**
Expand All @@ -570,7 +570,7 @@ public function testInsertSaftRegressionTest3()
);

$res = $this->fixture->query('SELECT * FROM <http://second-graph/> WHERE {?s ?p ?o.}');
$this->assertEquals(1, count($res['result']['rows']));
$this->assertEquals(1, \count($res['result']['rows']));
}

public function testMultipleInsertQuerysInDifferentGraphs()
Expand All @@ -580,13 +580,13 @@ public function testMultipleInsertQuerysInDifferentGraphs()
$this->fixture->query('INSERT INTO <http://graph2/> {<http://foo/1> <http://foo/2> <http://foo/3> . }');

$res = $this->fixture->query('SELECT * FROM <http://graph1/> WHERE {?s ?p ?o.}');
$this->assertEquals(1, count($res['result']['rows']));
$this->assertEquals(1, \count($res['result']['rows']));

$res = $this->fixture->query('SELECT * FROM <http://graph2/> WHERE {?s ?p ?o.}');
$this->assertEquals(1, count($res['result']['rows']));
$this->assertEquals(1, \count($res['result']['rows']));

$res = $this->fixture->query('SELECT * WHERE {?s ?p ?o.}');
$this->assertEquals(3, count($res['result']['rows']));
$this->assertEquals(3, \count($res['result']['rows']));

$this->markTestSkipped(
'Adding the same triple into two graphs does not work.'
Expand Down

0 comments on commit 5ee46fb

Please sign in to comment.