Skip to content

Commit

Permalink
Avoid substring allocation in Environment.ReadXdgDirectory (#103765)
Browse files Browse the repository at this point in the history
* Avoid substring allocation in Environment.ReadXdgDirectory

* Update src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>

---------

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
  • Loading branch information
stephentoub and am11 authored Jun 21, 2024
1 parent fc70f8b commit 66cffdf
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,10 @@ private static string ReadXdgDirectory(string homeDir, string key, string fallba
int endPos = line.IndexOf('"', pos);
if (endPos <= pos) continue;

// Got we need. Now extract it.
string path = line.Substring(pos, endPos - pos);
// Got what we need. Now extract it.
return relativeToHome ?
Path.Combine(homeDir, path) :
path;
Path.Join(homeDir, line.AsSpan(pos, endPos - pos)) :
line.Substring(pos, endPos - pos);
}
}
}
Expand Down

0 comments on commit 66cffdf

Please sign in to comment.