Remove test functions in loop whenever it's possible

This commit is contained in:
Romain Neutron
2013-11-13 14:32:02 +01:00
parent 21f0df2cfe
commit 954ba1c0b4
2 changed files with 25 additions and 6 deletions

View File

@@ -366,9 +366,13 @@ class ArchiveJob extends AbstractJob
$xpath = new \DOMXPath($dom);
for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) {
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
usleep(10);
if (!$this->isStarted()) {
break;
}
// make xml lighter (free ram)
foreach (array("size", "ctime", "mtime") as $k) {
$n->removeAttribute($k);
@@ -472,7 +476,10 @@ class ArchiveJob extends AbstractJob
}
// scan again for unmatched files
for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) {
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
if (!$this->isStarted()) {
break;
}
if (!$n->getAttribute('isdir') == '1' && !$n->getAttribute('match')) {
// still no match, now it's an error (bubble to the top)
for ($nn = $n; $nn && $nn->nodeType == XML_ELEMENT_NODE; $nn = $nn->parentNode) {
@@ -492,9 +499,13 @@ class ArchiveJob extends AbstractJob
}
$nodesToDel = array();
for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) {
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
usleep(10);
if (!$this->isStarted()) {
break;
}
if ($n->getAttribute('temperature') == 'hot') {
// do not move hotfiles
continue;
@@ -557,9 +568,13 @@ class ArchiveJob extends AbstractJob
}
$nodesToDel = array();
for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) {
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
usleep(10);
if (!$this->isStarted()) {
break;
}
if ($n->getAttribute('temperature') == 'hot') {
continue;
}
@@ -1082,7 +1097,10 @@ class ArchiveJob extends AbstractJob
private function archiveFilesToGrp(Application $app, \databox $databox, \DOMDocument $dom, \DOMElement $node, $path, $path_archived, $path_error, $grp_rid, $stat0, $stat1, $moveError, $moveArchived)
{
$nodesToDel = array();
for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) {
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
if (!$this->isStarted()) {
break;
}
if ($n->getAttribute('isdir') == '1') {
// in a grp, all levels goes in the same grp
$node->setAttribute('archived', '1'); // the main grp folder is 'keep'ed, but not subfolders

View File

@@ -1586,8 +1586,9 @@ class unicode
$out = '';
$_map = &self::$map[$target]; // faster in loop
$length = mb_strlen($string, 'UTF-8');
for ($i = 0; $i < mb_strlen($string, 'UTF-8'); $i++) {
for ($i = 0; $i < $length; $i++) {
if (true === array_key_exists(($c = mb_substr($string, $i, 1, 'UTF-8')), $_map)) {
$out .= $_map[$c];
} else {