~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cache_utf8.py

  • Committer: Robert Collins
  • Date: 2007-03-07 05:41:58 UTC
  • mto: (2321.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: robertc@robertcollins.net-20070307054158-j7yh62s59nz3rqdy
Update NEWS and clean out BRANCH.TODO.

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"""
21
21
 
22
 
from __future__ import absolute_import
23
 
 
24
22
import codecs
25
23
 
26
 
_utf8_encode = codecs.utf_8_encode
27
 
_utf8_decode = codecs.utf_8_decode
 
24
 
 
25
_utf8_encode = codecs.getencoder("utf-8")
 
26
_utf8_decode = codecs.getdecoder("utf-8")
 
27
# wrap _utf8_decode to support None->None for optional strings.
28
28
def _utf8_decode_with_None(bytestring, _utf8_decode=_utf8_decode):
29
 
    """wrap _utf8_decode to support None->None for optional strings.
30
 
 
31
 
    Also, only return the Unicode portion, since we don't care about the second
32
 
    return value.
33
 
    """
34
29
    if bytestring is None:
35
 
        return None
 
30
        return (None, 0)
36
31
    else:
37
 
        return _utf8_decode(bytestring)[0]
 
32
        return _utf8_decode(bytestring)
38
33
 
39
34
# Map revisions from and to utf8 encoding
40
35
# Whenever we do an encode/decode operation, we save the result, so that
50
45
    """Take this unicode revision id, and get a unicode version"""
51
46
    # If the key is in the cache try/KeyError is 50% faster than
52
47
    # val = dict.get(key), if val is None:
53
 
    # On jam's machine the difference is
54
 
    # try/KeyError:  900ms
55
 
    #      if None: 1250ms
 
48
    # On jam's machine the difference is 
 
49
    # try/KeyError:  900ms 
 
50
    #      if None: 1250ms 
56
51
    # Since these are primarily used when iterating over a knit entry
57
52
    # *most* of the time the key will already be in the cache, so use the
58
53
    # fast path