Repository navigation
Conversation
…n PathHelpers Replace Path.DirectorySeparatorChar.ToString() and EndsWith(string) with a zero-allocation character index check on the last string character. Additionally, reuse static fields for PathSeparators array and InvalidFileNameCharsSet to eliminate per-call heap allocations.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
🔵 Needs a closer look
Required CI checks and test results remain unverified, so the repository’s approval requirements are not yet confirmed.
No open issues 🎉
What changed in this PR
Optimizes path validation in the Appium .NET client by reducing repeated allocations and simplifying directory-separator checks.
Changes:
- Caches path separators and invalid filename characters for reuse.
- Replaces linear character lookups with
HashSetlookups. - Checks the trailing directory separator directly instead of using string comparisons.
| File | Description |
|---|---|
src/Appium.Net/Appium/PathHelpers.cs |
Reduces allocations in path validation and symbolic-link path splitting. |
Review effort: Balanced
…n PathHelpers Replace Path.DirectorySeparatorChar.ToString() and EndsWith(string) with a zero-allocation character index check on the last string character. Additionally, reuse static fields for PathSeparators array and InvalidFileNameCharsSet to eliminate per-call heap allocations. Also cache element.Rect in TouchByCoordinatesTestCase to prevent StaleElementReferenceException.
💡 What:
Optimized
PathHelpers.ValidateAndGetFullPathandContainsSymlinkWithinBaseDirectoryinAppium.Net:!allowedDirectory.EndsWith(Path.DirectorySeparatorChar.ToString()) && !allowedDirectory.EndsWith(Path.AltDirectorySeparatorChar.ToString())with a direct check onallowedDirectory[allowedDirectory.Length - 1].char[] PathSeparatorsfield andHashSet<char> InvalidFileNameCharsSetfield to eliminate repeated allocations of separator arrays and invalid file name char arrays, replacing linear array lookups (Array.IndexOf) with O(1) set lookups.🎯 Why:
.ToString()onPath.DirectorySeparatorCharandPath.AltDirectorySeparatorCharallocated string instances on every call toValidateAndGetFullPath, andEndsWith(string)performed string comparison operations. Furthermore,Path.GetInvalidFileNameChars()and array allocations on path splits incurred unnecessary heap allocations.📊 Measured Improvement:
In a benchmark of 1,000,000 calls to
ValidateAndGetFullPath:PR created automatically by Jules for task 4938572749104182767 started by @Dor-bl