summaryrefslogtreecommitdiffstats
path: root/Python/formatter_unicode.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2012-01-03 23:33:50 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2012-01-03 23:33:50 (GMT)
commit3fe553160c785f76ca908500a7531fceb2176203 (patch)
tree92adb3edbe5e192bc48bf8b69a4c234f4d1f27b6 /Python/formatter_unicode.c
parent332503db07ab5f8c2dea301a7ec9b8f7d4f1152f (diff)
downloadcpython-3fe553160c785f76ca908500a7531fceb2176203.zip
cpython-3fe553160c785f76ca908500a7531fceb2176203.tar.gz
cpython-3fe553160c785f76ca908500a7531fceb2176203.tar.bz2
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.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
index 6deb3cd..ef01511 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;