[Python-modules-commits] [python-pyld] 38/276: Added optimization to avoid extra bnode sorting.
Wolfgang Borgert
debacle at moszumanska.debian.org
Wed Oct 8 23:47:51 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to branch master
in repository python-pyld.
commit a3d80416ad0f4136b68fd2364a2f0c919e891095
Author: Dave Longley <dlongley at digitalbazaar.com>
Date: Wed Nov 9 13:02:29 2011 -0500
Added optimization to avoid extra bnode sorting.
---
lib/pyld/jsonld.py | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index bc1e519..7ecaaf0 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -980,17 +980,21 @@ class Processor:
'refs': None
}
+ # define bnode sorting function
+ def bnodeSort(a, b):
+ return self.deepCompareBlankNodes(a, b)
+
# keep sorting and naming blank nodes until they are all named
+ resort = True
while len(bnodes) > 0:
- # define bnode sorting function
- def bnodeSort(a, b):
- return self.deepCompareBlankNodes(a, b)
-
- bnodes.sort(cmp=bnodeSort)
+ if resort:
+ bnodes.sort(cmp=bnodeSort)
# name all bnodes accoring to the first bnodes relation mappings
+ # (if it has mappings then a resort will be necessary)
bnode = bnodes.pop(0)
iri = bnode['@subject']['@iri']
+ resort = self.serializations[iri]['props'] is not None
dirs = ['props', 'refs']
for dir in dirs:
# if no serialization has been computed,
@@ -1016,15 +1020,17 @@ class Processor:
self.renameBlankNode(subjects[iriK], c14n.next())
renamed.append(iriK)
- # only keep non-canonically named bnodes
- tmp = bnodes
- bnodes = []
- for b in tmp:
- iriB = b['@subject']['@iri']
- if not c14n.inNamespace(iriB):
- for i2 in renamed:
- self.markSerializationDirty(iriB, i2, dir)
- bnodes.append(b)
+ # only clear serializations if resorting is necessary
+ if resort:
+ # only keep non-canonically named bnodes
+ tmp = bnodes
+ bnodes = []
+ for b in tmp:
+ iriB = b['@subject']['@iri']
+ if not c14n.inNamespace(iriB):
+ for i2 in renamed:
+ self.markSerializationDirty(iriB, i2, dir)
+ bnodes.append(b)
# sort property lists that now have canonically named bnodes
for key in edges['props']:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pyld.git
More information about the Python-modules-commits
mailing list