aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-02-03 12:24:12 -0700
committerTom Tromey <tromey@adacore.com>2022-03-07 07:52:59 -0700
commit36f5ca535d0cffb4d9767f4471ac632dddd94c3b (patch)
tree39057d90ece16a147883629e2f6e113d0d4798c9
parenta320f135ddb4726474394841a19f3e2cba216ff3 (diff)
downloadgdb-36f5ca535d0cffb4d9767f4471ac632dddd94c3b.zip
gdb-36f5ca535d0cffb4d9767f4471ac632dddd94c3b.tar.gz
gdb-36f5ca535d0cffb4d9767f4471ac632dddd94c3b.tar.bz2
Don't pre-size result string in ada_decode
Currently, ada_decode pre-sizes the output string, filling it with 'X' characters. However, it's a bit simpler and more flexible to let std::string do the work here, and simply append characters to the string as we go. This turns out to be useful for a subsequent patch.
-rw-r--r--gdb/ada-lang.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index d44b090..9a7ab72 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1004,7 +1004,7 @@ remove_compiler_suffix (const char *encoded, int *len)
std::string
ada_decode (const char *encoded, bool wrap)
{
- int i, j;
+ int i;
int len0;
const char *p;
int at_start_name;
@@ -1068,10 +1068,6 @@ ada_decode (const char *encoded, bool wrap)
if (len0 > 1 && startswith (encoded + len0 - 1, "B"))
len0 -= 1;
- /* Make decoded big enough for possible expansion by operator name. */
-
- decoded.resize (2 * len0 + 1, 'X');
-
/* Remove trailing __{digit}+ or trailing ${digit}+. */
if (len0 > 1 && isdigit (encoded[len0 - 1]))
@@ -1089,8 +1085,8 @@ ada_decode (const char *encoded, bool wrap)
/* The first few characters that are not alphabetic are not part
of any encoding we use, so we can copy them over verbatim. */
- for (i = 0, j = 0; i < len0 && !isalpha (encoded[i]); i += 1, j += 1)
- decoded[j] = encoded[i];
+ for (i = 0; i < len0 && !isalpha (encoded[i]); i += 1)
+ decoded.push_back (encoded[i]);
at_start_name = 1;
while (i < len0)
@@ -1107,10 +1103,9 @@ ada_decode (const char *encoded, bool wrap)
op_len - 1) == 0)
&& !isalnum (encoded[i + op_len]))
{
- strcpy (&decoded.front() + j, ada_opname_table[k].decoded);
+ decoded.append (ada_opname_table[k].decoded);
at_start_name = 0;
i += op_len;
- j += strlen (ada_opname_table[k].decoded);
break;
}
}
@@ -1214,21 +1209,18 @@ ada_decode (const char *encoded, bool wrap)
else if (i < len0 - 2 && encoded[i] == '_' && encoded[i + 1] == '_')
{
/* Replace '__' by '.'. */
- decoded[j] = '.';
+ decoded.push_back ('.');
at_start_name = 1;
i += 2;
- j += 1;
}
else
{
/* It's a character part of the decoded name, so just copy it
over. */
- decoded[j] = encoded[i];
+ decoded.push_back (encoded[i]);
i += 1;
- j += 1;
}
}
- decoded.resize (j);
/* Decoded names should never contain any uppercase character.
Double-check this, and abort the decoding if we find one. */