~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_chunks_to_lines_pyx.pyx

  • Committer: John Arbash Meinel
  • Date: 2008-12-11 03:08:03 UTC
  • mto: This revision was merged to the branch mainline in revision 3895.
  • Revision ID: john@arbash-meinel.com-20081211030803-gctunob7zsten3qg
Move everything into properly parameterized tests.

Also add tests that we preserve the object when it is already lines.

The compiled form takes 450us on a 7.6k line file (NEWS).
So for common cases, we should have virtually no overhead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    cdef char *newline
43
43
    cdef char *c_last
44
44
    cdef Py_ssize_t the_len
 
45
    cdef Py_ssize_t chunks_len
 
46
    cdef Py_ssize_t cur
45
47
 
46
48
    # Check to see if the chunks are already lines
 
49
    chunks_len = len(chunks)
 
50
    if chunks_len == 0:
 
51
        return chunks
 
52
    cur = 0
47
53
    for chunk in chunks:
 
54
        cur += 1
48
55
        PyString_AsStringAndSize(chunk, &c_str, &the_len)
49
56
        if the_len == 0:
50
57
            break
51
58
        c_last = c_str + the_len - 1
52
59
        newline = <char *>memchr(c_str, c'\n', the_len)
53
 
        if newline == NULL or newline != c_last:
 
60
        if newline != c_last and not (newline == NULL and cur == chunks_len):
54
61
            break
55
62
    else:
56
63
        return chunks