Skip to content

Commit adacf39

Browse files
mwinterberg-dteknormj
authored andcommitted
Removed temporary strings when converting bytes to their ASCII hex representation.
For large XML messages sent through SQS SendMessage, the time to UrlEncode the content can be significant.
1 parent 236e817 commit adacf39

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

sdk/src/Core/Amazon.Util/AWSSDKUtils.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,12 +1081,31 @@ public static string UrlEncode(int rfcNumber, string data, bool path)
10811081
}
10821082
else
10831083
{
1084-
encoded.Append("%").Append(string.Format(CultureInfo.InvariantCulture, "{0:X2}", (int)symbol));
1084+
encoded.Append('%');
1085+
1086+
// Break apart the byte into two four-bit components and
1087+
// then convert each into their hexadecimal equivalent.
1088+
byte b = (byte)symbol;
1089+
int hiNibble = b >> 4;
1090+
int loNibble = b & 0xF;
1091+
encoded.Append(ToUpperHex(hiNibble));
1092+
encoded.Append(ToUpperHex(loNibble));
10851093
}
10861094
}
10871095

10881096
return encoded.ToString();
10891097
}
1098+
1099+
private static char ToUpperHex(int value)
1100+
{
1101+
// Maps 0-9 to the Unicode range of '0' - '9' (0x30 - 0x39).
1102+
if (value <= 9)
1103+
{
1104+
return (char)(value + '0');
1105+
}
1106+
// Maps 10-15 to the Unicode range of 'A' - 'F' (0x41 - 0x46).
1107+
return (char)(value - 10 + 'A');
1108+
}
10901109

10911110
internal static string UrlEncodeSlash(string data)
10921111
{

0 commit comments

Comments
 (0)