Made sort optimization more effective.

This commit is contained in:
Dave Longley 2011-11-09 13:58:47 -05:00
parent af25c067de
commit 7e65429375

View file

@ -1889,6 +1889,7 @@ class JsonLdProcessor
{
if($resort)
{
$resort = false;
usort($bnodes, array($this, 'deepCompareBlankNodes'));
}
@ -1927,9 +1928,6 @@ class JsonLdProcessor
}
}
// only clear serializations if resorting is necessary
if($resort)
{
// only keep non-canonically named bnodes
$tmp = $bnodes;
$bnodes = array();
@ -1941,14 +1939,17 @@ class JsonLdProcessor
// mark serializations related to the named bnodes as dirty
foreach($renamed as $r)
{
$this->markSerializationDirty($iriB, $r, $dir);
if($this->markSerializationDirty($iriB, $r, $dir))
{
// resort if a serialization was marked dirty
$resort = true;
}
}
$bnodes[] = $b;
}
}
}
}
}
// sort property lists that now have canonically-named bnodes
foreach($edges->props as $key => $value)
@ -1974,14 +1975,19 @@ class JsonLdProcessor
* @param iri the IRI of the bnode to check.
* @param changed the old IRI of the bnode that changed.
* @param dir the direction to check ('props' or 'refs').
*
* @return true if the serialization was marked dirty, false if not.
*/
public function markSerializationDirty($iri, $changed, $dir)
{
$rval = false;
$s = $this->serializations->$iri;
if($s->$dir !== null and property_exists($s->$dir->m, $changed))
{
$s->$dir = null;
$rval = true;
}
return $rval;
}
/**