Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-24 - WslPathResolver string splitting
**Learning:** `WslPathResolver.TryParseUncRemainder` used `string.Split()`, `string.Join()`, and `Enumerable.Skip()` which leads to unnecessary GC pressure and multiple string/array allocations for hot path code.
**Action:** Replace `string.Split` with `ReadOnlySpan<char>.Split` and use `StringBuilder` to append portions sequentially when parsing and reconstructing path parts. This saves multiple array/string allocations and makes parsing faster.
Comment on lines +1 to +3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ“ Maintainability & Code Quality | 🟑 Minor | ⚑ Quick win

Fix the Markdown heading structure.

markdownlint reports MD041 because the file starts with an h2 heading. It also reports MD022 because the heading has no blank line after it. Change the first heading to h1 and add a blank line.

Proposed fix
-## 2024-05-24 - WslPathResolver string splitting
+# 2024-05-24 - WslPathResolver string splitting
+
 **Learning:** `WslPathResolver.TryParseUncRemainder` used `string.Split()`, `string.Join()`, and `Enumerable.Skip()` which leads to unnecessary GC pressure and multiple string/array allocations for hot path code.
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## 2024-05-24 - WslPathResolver string splitting
**Learning:** `WslPathResolver.TryParseUncRemainder` used `string.Split()`, `string.Join()`, and `Enumerable.Skip()` which leads to unnecessary GC pressure and multiple string/array allocations for hot path code.
**Action:** Replace `string.Split` with `ReadOnlySpan<char>.Split` and use `StringBuilder` to append portions sequentially when parsing and reconstructing path parts. This saves multiple array/string allocations and makes parsing faster.
# 2024-05-24 - WslPathResolver string splitting
**Learning:** `WslPathResolver.TryParseUncRemainder` used `string.Split()`, `string.Join()`, and `Enumerable.Skip()` which leads to unnecessary GC pressure and multiple string/array allocations for hot path code.
**Action:** Replace `string.Split` with `ReadOnlySpan<char>.Split` and use `StringBuilder` to append portions sequentially when parsing and reconstructing path parts. This saves multiple array/string allocations and makes parsing faster.
🧰 Tools
πŸͺ› LanguageTool

[style] ~3-~3: Consider using a different verb to strengthen your wording.
Context: ...s multiple array/string allocations and makes parsing faster.

(MAKE_XXX_FASTER)

πŸͺ› markdownlint-cli2 (0.23.1)

[warning] 1-1: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


[warning] 1-1: First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.jules/bolt.md around lines 1 - 3, Update the first heading in the
WslPathResolver learning entry from h2 to h1, then add a blank line immediately
after it so the document satisfies MD041 and MD022.

Source: Linters/SAST tools

31 changes: 27 additions & 4 deletions QuickShell.Core/Services/WslPathResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,39 @@
private static bool TryParseUncRemainder(string remainder, string fullUnc, out WslLocation location)
{
location = null!;
var parts = remainder.Split('\\', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 2)
// Bolt: Performance optimization - avoid string.Split(), Linq Skip(), and string.Join() allocations.
var span = remainder.AsSpan();
string? distro = null;
var linuxPathBuilder = new System.Text.StringBuilder(span.Length);

foreach (var range in span.Split('\\'))
{
var part = span[range];
if (part.IsEmpty)
{
continue;
}

if (distro is null)
{
distro = part.ToString();
}
else
{
linuxPathBuilder.Append('/');
linuxPathBuilder.Append(part);
}
}

if (linuxPathBuilder.Length == 0 || distro is null)
{
return false;
}

location = new WslLocation
{
Distro = parts[0],
LinuxPath = "/" + string.Join('/', parts.Skip(1)),
Distro = distro,
LinuxPath = linuxPathBuilder.ToString(),
Comment on lines +150 to +177

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | ⚑ Quick win

Add direct tests for UNC remainder parsing.

WslPathResolverTests.cs does not directly exercise this parser. Add cases for both \\wsl$\ and \\wsl.localhost\, repeated separators, trailing separators, a missing distro, and a missing Linux path. Assert Distro, LinuxPath, UncPath, and rejected inputs. This protects the span iteration and validation contract.

🧰 Tools
πŸͺ› GitHub Check: CodeQL

[warning] 150-150: Useless assignment to local variable
This assignment to range is useless, since its value is never read.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@QuickShell.Core/Services/WslPathResolver.cs` around lines 150 - 177, Add
direct tests in WslPathResolverTests for UNC remainder parsing, covering both
\\wsl$\ and \\wsl.localhost\ prefixes, repeated and trailing separators, missing
distro, and missing Linux path. Assert the resulting Distro, LinuxPath, and
UncPath values for valid inputs, and verify invalid inputs are rejected,
targeting the parser behavior implemented around the span iteration and
validation checks.

Source: MCP tools

UncPath = fullUnc,
};

Expand Down
Loading