Skip to content

Commit e8f5ed0

Browse files
committed
Optimize use of Span in Bytes
1 parent 533403c commit e8f5ed0

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/core/IronPython/Runtime/Bytes.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public static object fromhex(CodeContext context, [NotNone] PythonType cls, [Not
375375
return PythonTypeOps.CallParams(context, cls, new Bytes(hex));
376376
}
377377

378-
public string hex() => ToHex(_bytes.AsSpan()); // new in CPython 3.5
378+
public string hex() => ToHex(_bytes); // new in CPython 3.5
379379

380380
internal static string ToHex(ReadOnlySpan<byte> bytes) {
381381
if (bytes.Length == 0) return string.Empty;
@@ -395,13 +395,13 @@ static char ToAscii(int b) {
395395
// new in CPython 3.8
396396
public string hex([NotNone] string sep, int bytes_per_sep = 1) {
397397
if (sep.Length != 1) throw PythonOps.ValueError($"{nameof(sep)} must be length 1");
398-
return ToHex(_bytes.AsSpan(), sep[0], bytes_per_sep);
398+
return ToHex(_bytes, sep[0], bytes_per_sep);
399399
}
400400

401401
// new in CPython 3.8
402402
public string hex([BytesLike, NotNone] IList<byte> sep, int bytes_per_sep = 1) {
403403
if (sep.Count != 1) throw PythonOps.ValueError($"{nameof(sep)} must be length 1");
404-
return ToHex(_bytes.AsSpan(), (char)sep[0], bytes_per_sep);
404+
return ToHex(_bytes, (char)sep[0], bytes_per_sep);
405405
}
406406

407407
internal static string ToHex(ReadOnlySpan<byte> bytes, char sep, int bytes_per_sep) {
@@ -1077,9 +1077,9 @@ public int this[object? index] {
10771077

10781078
#region Implementation Details
10791079

1080-
internal ReadOnlyMemory<byte> AsMemory() => _bytes.AsMemory();
1080+
internal ReadOnlyMemory<byte> AsMemory() => _bytes;
10811081

1082-
internal ReadOnlySpan<byte> AsSpan() => _bytes.AsSpan();
1082+
internal ReadOnlySpan<byte> AsSpan() => _bytes;
10831083

10841084
internal static bool TryInvokeBytesOperator(CodeContext context, object? obj, [NotNullWhen(true)] out Bytes? bytes) {
10851085
if (PythonTypeOps.TryInvokeUnaryOperator(context, obj, "__bytes__", out object? res)) {

0 commit comments

Comments
 (0)