summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-12-04 08:30:24 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-12-04 08:30:24 (GMT)
commit8dbd421b4d48d31891d159d8c581ea7c0b15226d (patch)
tree6c204ad876aa635f413b8856ce91bcbc8e89a201
parentd45c7f8d74d30de0a558b10e04541b861428b7c1 (diff)
downloadcpython-8dbd421b4d48d31891d159d8c581ea7c0b15226d.zip
cpython-8dbd421b4d48d31891d159d8c581ea7c0b15226d.tar.gz
cpython-8dbd421b4d48d31891d159d8c581ea7c0b15226d.tar.bz2
Cleanup unicodeobject.c
* Remove micro-optization: (errors == "surrogateescape" || strcmp(errors, "surrogateescape") == 0). Only use strcmp() * Initialize 'arg' members in unicode_format_arg() to help the compiler to diagnose real bugs and also make the code simpler to read
-rw-r--r--Objects/unicodeobject.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 6491fdc..0451f0d 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3110,8 +3110,7 @@ locale_error_handler(const char *errors, int *surrogateescape)
*surrogateescape = 0;
return 0;
}
- if (errors == "surrogateescape"
- || strcmp(errors, "surrogateescape") == 0) {
+ if (strcmp(errors, "surrogateescape") == 0) {
*surrogateescape = 1;
return 0;
}
@@ -13438,7 +13437,6 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx,
PyObject *v;
- arg->ch = FORMAT_READ(ctx);
if (arg->ch == '(') {
/* Get argument value from a dictionary. Example: "%(name)s". */
Py_ssize_t keystart;
@@ -13487,7 +13485,6 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx,
}
/* Parse flags. Example: "%+i" => flags=F_SIGN. */
- arg->flags = 0;
while (--ctx->fmtcnt >= 0) {
arg->ch = FORMAT_READ(ctx);
ctx->fmtpos++;
@@ -13502,7 +13499,6 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx,
}
/* Parse width. Example: "%10s" => width=10 */
- arg->width = -1;
if (arg->ch == '*') {
v = unicode_format_getnextarg(ctx);
if (v == NULL)
@@ -13544,7 +13540,6 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx,
}
/* Parse precision. Example: "%.3f" => prec=3 */
- arg->prec = -1;
if (arg->ch == '.') {
arg->prec = 0;
if (--ctx->fmtcnt >= 0) {
@@ -13613,9 +13608,12 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx,
- "e", "E", "f", "F", "g", "G": float
- "c": int or str (1 character)
+ When possible, the output is written directly into the Unicode writer
+ (ctx->writer). A string is created when padding is required.
+
Return 0 if the argument has been formatted into *p_str,
1 if the argument has been written into ctx->writer,
- -1 on error. */
+ -1 on error. */
static int
unicode_format_arg_format(struct unicode_formatter_t *ctx,
struct unicode_format_arg_t *arg,
@@ -13639,10 +13637,8 @@ unicode_format_arg_format(struct unicode_formatter_t *ctx,
if (v == NULL)
return -1;
- arg->sign = 0;
switch (arg->ch) {
-
case 's':
case 'r':
case 'a':
@@ -13894,6 +13890,13 @@ unicode_format_arg(struct unicode_formatter_t *ctx)
PyObject *str;
int ret;
+ arg.ch = PyUnicode_READ(ctx->fmtkind, ctx->fmtdata, ctx->fmtpos);
+ arg.flags = 0;
+ arg.width = -1;
+ arg.prec = -1;
+ arg.sign = 0;
+ str = NULL;
+
ret = unicode_format_arg_parse(ctx, &arg);
if (ret == -1)
return -1;