[Zodb-checkins] CVS: Packages/ZConfig - SchemaInfo.py:1.1.2.5

Fred L. Drake, Jr. fred@zope.com
Mon, 9 Dec 2002 13:09:15 -0500


Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv20028

Modified Files:
      Tag: zconfig-schema-devel-branch
	SchemaInfo.py 
Log Message:
Change the key lookup mechanics in SectionInfo.


=== Packages/ZConfig/SchemaInfo.py 1.1.2.4 => 1.1.2.5 ===
--- Packages/ZConfig/SchemaInfo.py:1.1.2.4	Mon Dec  9 12:58:12 2002
+++ Packages/ZConfig/SchemaInfo.py	Mon Dec  9 13:09:14 2002
@@ -71,15 +71,17 @@
         self.keytype = keytype
         self.names = names
         self.nametype = nametype
-        self._children = [] # list of (name, info) pairs
+        self._children = []
+        self._keyindex = {}
         KeyInfo.__init__(self, name, datatype, minOccurs, maxOccurs,
                          handler)
 
     def _add_child(self, name, thing):
-        for n, c in self._children:
-            if name == n:
-                raise ValueError("child name %s already used" % name)
-        self._children.append((name, thing))
+        if name in self._keyindex:
+            raise ValueError("child name %s already used" % name)
+        index = len(self._children)
+        self._children.append(thing)
+        self._keyindex[name] = index, thing
 
     def addkey(self, keyinfo):
         self._add_child(keyinfo.name, keyinfo)
@@ -91,13 +93,17 @@
         self._add_child(name, sectinfo)
 
     def getinfo(self, name):
-        for n, c in self._children:
-            if n == name:
-                return c
-        return None
+        try:
+            index, thing = self._keyindex[name]
+        except KeyError:
+            return None
+        else:
+            return thing
 
     def getchildnames(self):
-        return [n for (n, c) in self._children]
+        L = [(i,n) for (n,i,t) in self._keyindex.iteritems()]
+        L.sort()
+        return [i for (i,n) in L]
 
     def issection(self):
         return True