Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/IronPython/Hosting/PythonOptionsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ protected override void ParseArgument(string/*!*/ arg) {
}

if (arg == "/?" || arg == "--help") {
HandleOptions("h".AsSpan());
HandleOptions("h");
return;
}

if (arg == "--version") {
HandleOptions("V".AsSpan());
HandleOptions("V");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/IronPython/Modules/_io/StringIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private string readline(int limit) {
span = span.Slice(0, idx + 1);
}
} else if (_newline == string.Empty) {
var idx = span.IndexOfAny("\r\n".AsSpan());
var idx = span.IndexOfAny("\r\n");
if (idx != -1) {
if (span[idx++] == '\r') {
// ensure we don't split \r\n
Expand Down Expand Up @@ -377,7 +377,7 @@ private int DoWrite(string str) {

if (_newline is null) {
while (true) {
var idx = span.IndexOfAny("\r\n".AsSpan());
var idx = span.IndexOfAny("\r\n");
if (idx == -1)
break;

Expand Down
10 changes: 5 additions & 5 deletions src/core/IronPython/Runtime/Bytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public static object fromhex(CodeContext context, [NotNone] PythonType cls, [Not
return PythonTypeOps.CallParams(context, cls, new Bytes(hex));
}

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

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

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

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

#region Implementation Details

internal ReadOnlyMemory<byte> AsMemory() => _bytes.AsMemory();
internal ReadOnlyMemory<byte> AsMemory() => _bytes;

internal ReadOnlySpan<byte> AsSpan() => _bytes.AsSpan();
internal ReadOnlySpan<byte> AsSpan() => _bytes;

internal static bool TryInvokeBytesOperator(CodeContext context, object? obj, [NotNullWhen(true)] out Bytes? bytes) {
if (PythonTypeOps.TryInvokeUnaryOperator(context, obj, "__bytes__", out object? res)) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/IronPython/Runtime/LiteralParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void handleError(in ReadOnlySpan<T> data, int start, int end, string reason) {
#nullable enable

private static bool TryParseExpression(Parser parser, ReadOnlySpan<char> data, [NotNullWhen(true)] out Expression? expression, [NotNullWhen(false)] out string? error) {
if (data.TrimStart(" \t\f\r\n".AsSpan()).Length == 0) {
if (data.TrimStart(" \t\f\r\n").Length == 0) {
expression = null;
error = "f-string: empty expression not allowed";
return false;
Expand Down Expand Up @@ -649,7 +649,7 @@ private static bool TryParseInt<T>(in ReadOnlySpan<T> text, int start, int lengt
}

public static object ParseInteger(string text, int b) {
if (TryParseInteger(text.AsSpan(), b, false, out object val)) {
if (TryParseInteger(text, b, false, out object val)) {
return val;
}
throw new ValueErrorException($"invalid literal with base {b}: {text}");
Expand Down
4 changes: 0 additions & 4 deletions src/core/IronPython/Runtime/Operations/PythonOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3689,10 +3689,6 @@ internal static string MakeString(this IList<byte> bytes, int startIdx, int maxB
return StringOps.Latin1Encoding.GetString(byteArr, startIdx, maxBytes);
}

internal static string MakeString(this Span<byte> bytes) {
return MakeString((ReadOnlySpan<byte>)bytes);
}

internal static string MakeString(this ReadOnlySpan<byte> bytes) {
if (bytes.IsEmpty) {
return string.Empty;
Expand Down
Loading