diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2012-01-04 00:33:50 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2012-01-04 00:33:50 +0100 |
commit | 6ebaf24a65c493bffaccd39bacf38b12e4604fec (patch) | |
tree | 36497fd986c8add8af7bc04a4917f7b9e8ae2f9f /Python/formatter_unicode.c | |
parent | 40c6a9f4554fff8a8fa7e09805f093f9e8bdcf3a (diff) | |
download | cpython-6ebaf24a65c493bffaccd39bacf38b12e4604fec.tar.gz |
Add a new PyUnicode_Fill() function
It is faster than the unicode_fill() function which was implemented in
formatter_unicode.c.
Diffstat (limited to 'Python/formatter_unicode.c')
-rw-r--r-- | Python/formatter_unicode.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index 6deb3cd7fe..ef0151192b 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -317,15 +317,6 @@ calc_padding(Py_ssize_t nchars, Py_ssize_t width, Py_UCS4 align, *n_rpadding = *n_total - nchars - *n_lpadding; } -static void -unicode_fill(PyObject *str, Py_ssize_t start, Py_ssize_t end, Py_UCS4 ch) -{ - int kind = PyUnicode_KIND(str); - void *data = PyUnicode_DATA(str); - while (start < end) - PyUnicode_WRITE(kind, data, start++, ch); -} - /* Do the padding, and return a pointer to where the caller-supplied content goes. */ static Py_ssize_t @@ -335,12 +326,12 @@ fill_padding(PyObject *s, Py_ssize_t start, Py_ssize_t nchars, { /* Pad on left. */ if (n_lpadding) - unicode_fill(s, start, start + n_lpadding, fill_char); + PyUnicode_Fill(s, start, start + n_lpadding, fill_char); /* Pad on right. */ if (n_rpadding) - unicode_fill(s, start + nchars + n_lpadding, - start + nchars + n_lpadding + n_rpadding, fill_char); + PyUnicode_Fill(s, start + nchars + n_lpadding, + start + nchars + n_lpadding + n_rpadding, fill_char); /* Pointer to the user content. */ return start + n_lpadding; @@ -557,7 +548,7 @@ fill_number(PyObject *out, Py_ssize_t pos, const NumberFieldWidths *spec, #endif if (spec->n_lpadding) { - unicode_fill(out, pos, pos + spec->n_lpadding, fill_char); + PyUnicode_Fill(out, pos, pos + spec->n_lpadding, fill_char); pos += spec->n_lpadding; } if (spec->n_sign == 1) { @@ -581,7 +572,7 @@ fill_number(PyObject *out, Py_ssize_t pos, const NumberFieldWidths *spec, pos += spec->n_prefix; } if (spec->n_spadding) { - unicode_fill(out, pos, pos + spec->n_spadding, fill_char); + PyUnicode_Fill(out, pos, pos + spec->n_spadding, fill_char); pos += spec->n_spadding; } @@ -640,7 +631,7 @@ fill_number(PyObject *out, Py_ssize_t pos, const NumberFieldWidths *spec, } if (spec->n_rpadding) { - unicode_fill(out, pos, pos + spec->n_rpadding, fill_char); + PyUnicode_Fill(out, pos, pos + spec->n_rpadding, fill_char); pos += spec->n_rpadding; } return 0; |