Rev 4767: Expose bzrlib.static_tuple.StaticTuple as a thunk in http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple-btree-string-intern
John Arbash Meinel
john at arbash-meinel.com
Mon Oct 12 21:02:32 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple-btree-string-intern
------------------------------------------------------------
revno: 4767
revision-id: john at arbash-meinel.com-20091012200227-dc9uy4l5487eezcy
parent: john at arbash-meinel.com-20091012195025-hiwyvwgdgz1duqj3
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-static-tuple-btree-string-intern
timestamp: Mon 2009-10-12 15:02:27 -0500
message:
Expose bzrlib.static_tuple.StaticTuple as a thunk
which selects between the C or pure-python version.
Note a couple of places where I would like to start using it.
-------------- next part --------------
=== modified file 'bzrlib/btree_index.py'
--- a/bzrlib/btree_index.py 2009-09-22 02:18:24 +0000
+++ b/bzrlib/btree_index.py 2009-10-12 20:02:27 +0000
@@ -163,6 +163,7 @@
node_refs, _ = self._check_key_ref_value(key, references, value)
if key in self._nodes:
raise errors.BadIndexDuplicateKey(key, self)
+ # TODO: StaticTuple
self._nodes[key] = (node_refs, value)
self._keys.add(key)
if self._nodes_by_key is not None and self._key_length > 1:
@@ -625,6 +626,7 @@
for line in lines[2:]:
if line == '':
break
+ # TODO: Switch to StaticTuple here.
nodes.append(tuple(map(intern, line.split('\0'))))
return nodes
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py 2009-10-08 15:44:41 +0000
+++ b/bzrlib/index.py 2009-10-12 20:02:27 +0000
@@ -40,7 +40,7 @@
debug,
errors,
)
-from bzrlib._static_tuple_c import StaticTuple
+from bzrlib.static_tuple import StaticTuple
_HEADER_READV = (0, 200)
_OPTION_KEY_ELEMENTS = "key_elements="
=== added file 'bzrlib/static_tuple.py'
--- a/bzrlib/static_tuple.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/static_tuple.py 2009-10-12 20:02:27 +0000
@@ -0,0 +1,25 @@
+# Copyright (C) 2009 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Interface thunk for a StaticTuple implementation."""
+
+try:
+ from bzrlib._static_tuple_c import StaticTuple
+except ImportError, e:
+ from bzrlib import osutils
+ osutils.failed_to_load_extension(e)
+ from bzrlib._static_tuple_py import StaticTuple
+
=== modified file 'bzrlib/tests/test__static_tuple.py'
--- a/bzrlib/tests/test__static_tuple.py 2009-10-07 19:34:22 +0000
+++ b/bzrlib/tests/test__static_tuple.py 2009-10-12 20:02:27 +0000
@@ -23,6 +23,7 @@
_static_tuple_py,
errors,
osutils,
+ static_tuple,
tests,
)
@@ -383,3 +384,13 @@
if self.module is _static_tuple_py:
return
self.assertIsNot(None, self.module._C_API)
+
+ def test_static_tuple_thunk(self):
+ # Make sure the right implementation is available from
+ # bzrlib.static_tuple.StaticTuple.
+ if self.module is _static_tuple_py:
+ if CompiledStaticTuple.available():
+ # We will be using the C version
+ return
+ self.assertIs(static_tuple.StaticTuple,
+ self.module.StaticTuple)
More information about the bazaar-commits
mailing list