Skip to content

Commit

Permalink
Mark some struct methods as readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Oct 14, 2019
1 parent bf28cbd commit c99f7dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Markdig/Helpers/StringLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public StringLine(ref StringSlice slice, int line, int column, int position)
return line.Slice;
}

public override string ToString()
public readonly override string ToString()
{
return Slice.ToString();
}
Expand Down
10 changes: 5 additions & 5 deletions src/Markdig/Helpers/StringLineGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Add(StringSlice slice)
Lines[Count++] = new StringLine(ref slice);
}

public override string ToString()
public readonly override string ToString()
{
return ToSlice().ToString();
}
Expand All @@ -112,7 +112,7 @@ public override string ToString()
/// </summary>
/// <param name="lineOffsets">The position of the `\n` line offsets from the beginning of the returned slice.</param>
/// <returns>A single slice concatenating the lines of this instance</returns>
public StringSlice ToSlice(List<LineOffset> lineOffsets = null)
public readonly StringSlice ToSlice(List<LineOffset> lineOffsets = null)
{
// Optimization case when no lines
if (Count == 0)
Expand Down Expand Up @@ -165,7 +165,7 @@ public StringSlice ToSlice(List<LineOffset> lineOffsets = null)
/// Converts this instance into a <see cref="ICharIterator"/>.
/// </summary>
/// <returns></returns>
public Iterator ToCharIterator()
public readonly Iterator ToCharIterator()
{
return new Iterator(this);
}
Expand Down Expand Up @@ -236,7 +236,7 @@ public Iterator(StringLineGroup lines)

public int End { get; private set; }

public bool IsEmpty => Start > End;
public readonly bool IsEmpty => Start > End;

public int SliceIndex { get; private set; }

Expand Down Expand Up @@ -292,7 +292,7 @@ public char NextChar()
return CurrentChar;
}

public char PeekChar(int offset = 1)
public readonly char PeekChar(int offset = 1)
{
if (offset < 0) throw new ArgumentOutOfRangeException("Negative offset are not supported for StringLineGroup", nameof(offset));

Expand Down
24 changes: 12 additions & 12 deletions src/Markdig/Helpers/StringSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public char NextChar()
/// </summary>
/// <returns>The character at offset, returns `\0` if none.</returns>
[MethodImpl(MethodImplOptionPortable.AggressiveInlining)]
public char PeekChar()
public readonly char PeekChar()
{
int index = Start + 1;
return index <= End ? Text[index] : '\0';
Expand All @@ -135,7 +135,7 @@ public char PeekChar()
/// <param name="offset">The offset.</param>
/// <returns>The character at offset, returns `\0` if none.</returns>
[MethodImpl(MethodImplOptionPortable.AggressiveInlining)]
public char PeekChar(int offset)
public readonly char PeekChar(int offset)
{
var index = Start + offset;
return index >= Start && index <= End ? Text[index] : '\0';
Expand All @@ -146,7 +146,7 @@ public char PeekChar(int offset)
/// </summary>
/// <returns>The character at offset, returns `\0` if none.</returns>
[MethodImpl(MethodImplOptionPortable.AggressiveInlining)]
public char PeekCharAbsolute(int index)
public readonly char PeekCharAbsolute(int index)
{
string text = Text;
return (uint)index < (uint)text.Length ? text[index] : '\0';
Expand All @@ -159,7 +159,7 @@ public char PeekCharAbsolute(int index)
/// <param name="offset">The offset.</param>
/// <returns>The character at offset, returns `\0` if none.</returns>
[MethodImpl(MethodImplOptionPortable.AggressiveInlining)]
public char PeekCharExtra(int offset)
public readonly char PeekCharExtra(int offset)
{
var index = Start + offset;
var text = Text;
Expand All @@ -172,7 +172,7 @@ public char PeekCharExtra(int offset)
/// <param name="text">The text.</param>
/// <param name="offset">The offset.</param>
/// <returns><c>true</c> if the text matches; <c>false</c> otherwise</returns>
public bool Match(string text, int offset = 0)
public readonly bool Match(string text, int offset = 0)
{
return Match(text, End, offset);
}
Expand All @@ -184,7 +184,7 @@ public bool Match(string text, int offset = 0)
/// <param name="end">The end.</param>
/// <param name="offset">The offset.</param>
/// <returns><c>true</c> if the text matches; <c>false</c> otherwise</returns>
public bool Match(string text, int end, int offset)
public readonly bool Match(string text, int end, int offset)
{
var index = Start + offset;

Expand Down Expand Up @@ -230,7 +230,7 @@ public bool SkipSpacesToEndOfLineOrEndOfDocument()
/// <param name="text">The text.</param>
/// <param name="offset">The offset.</param>
/// <returns><c>true</c> if the text matches; <c>false</c> otherwise</returns>
public bool MatchLowercase(string text, int offset = 0)
public readonly bool MatchLowercase(string text, int offset = 0)
{
return MatchLowercase(text, End, offset);
}
Expand All @@ -242,7 +242,7 @@ public bool MatchLowercase(string text, int offset = 0)
/// <param name="end">The end.</param>
/// <param name="offset">The offset.</param>
/// <returns><c>true</c> if the text matches; <c>false</c> otherwise</returns>
public bool MatchLowercase(string text, int end, int offset)
public readonly bool MatchLowercase(string text, int end, int offset)
{
var index = Start + offset;

Expand All @@ -267,7 +267,7 @@ public bool MatchLowercase(string text, int end, int offset)
/// <param name="offset">The offset.</param>
/// <param name="ignoreCase">true if ignore case</param>
/// <returns><c>true</c> if the text was found; <c>false</c> otherwise</returns>
public int IndexOf(string text, int offset = 0, bool ignoreCase = false)
public readonly int IndexOf(string text, int offset = 0, bool ignoreCase = false)
{
offset += Start;
int length = End - offset + 1;
Expand All @@ -288,7 +288,7 @@ public int IndexOf(string text, int offset = 0, bool ignoreCase = false)
/// Searches for the specified character within this slice.
/// </summary>
/// <returns>A value >= 0 if the character was found, otherwise &lt; 0</returns>
public int IndexOf(char c)
public readonly int IndexOf(char c)
{
int start = Start;
int length = End - start + 1;
Expand Down Expand Up @@ -372,7 +372,7 @@ public void Trim()
/// <returns>
/// A <see cref="string" /> that represents this instance.
/// </returns>
public override string ToString()
public readonly override string ToString()
{
string text = Text;
int start = Start;
Expand All @@ -389,7 +389,7 @@ public override string ToString()
/// Determines whether this slice is empty or made only of whitespaces.
/// </summary>
/// <returns><c>true</c> if this slice is empty or made only of whitespaces; <c>false</c> otherwise</returns>
public bool IsEmptyOrWhitespace()
public readonly bool IsEmptyOrWhitespace()
{
for (int i = Start; i <= End; i++)
{
Expand Down

0 comments on commit c99f7dd

Please sign in to comment.