~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cache_utf8.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-02 16:51:24 UTC
  • mto: This revision was merged to the branch mainline in revision 2321.
  • Revision ID: john@arbash-meinel.com-20070302165124-pzxf42224e9j7ju2
Update the 'escaped store' tests to use both unicode and utf8 file ids.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
# TODO: Some kind of command-line display of revision properties:
 
17
# TODO: Some kind of command-line display of revision properties: 
18
18
# perhaps show them in log -v and allow them as options to the commit command.
19
19
 
20
20
"""Some functions to enable caching the conversion between unicode to utf8"""
22
22
import codecs
23
23
 
24
24
 
25
 
_utf8_encode = codecs.utf_8_encode
26
 
_utf8_decode = codecs.utf_8_decode
27
 
def _utf8_decode_with_None(bytestring, _utf8_decode=_utf8_decode):
28
 
    """wrap _utf8_decode to support None->None for optional strings.
29
 
 
30
 
    Also, only return the Unicode portion, since we don't care about the second
31
 
    return value.
32
 
    """
33
 
    if bytestring is None:
34
 
        return None
35
 
    else:
36
 
        return _utf8_decode(bytestring)[0]
 
25
_utf8_encode = codecs.getencoder("utf-8")
 
26
_utf8_decode = codecs.getdecoder("utf-8")
37
27
 
38
28
# Map revisions from and to utf8 encoding
39
29
# Whenever we do an encode/decode operation, we save the result, so that
49
39
    """Take this unicode revision id, and get a unicode version"""
50
40
    # If the key is in the cache try/KeyError is 50% faster than
51
41
    # val = dict.get(key), if val is None:
52
 
    # On jam's machine the difference is
53
 
    # try/KeyError:  900ms
54
 
    #      if None: 1250ms
 
42
    # On jam's machine the difference is 
 
43
    # try/KeyError:  900ms 
 
44
    #      if None: 1250ms 
55
45
    # Since these are primarily used when iterating over a knit entry
56
46
    # *most* of the time the key will already be in the cache, so use the
57
47
    # fast path