Skip to content

Commit e7ad62d

Browse files
committed
Address Jason's comments
1 parent f7d8768 commit e7ad62d

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

PSReadLine/Cmdlets.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Collections.ObjectModel;
99
using System.Diagnostics.CodeAnalysis;
1010
using System.Globalization;
11-
using System.IO;
1211
using System.Management.Automation;
1312
using System.Management.Automation.Language;
1413
using System.Reflection;
@@ -639,9 +638,7 @@ public string HistorySavePath
639638
get => _historySavePath;
640639
set
641640
{
642-
// Normalize the path
643-
var altPathChar = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? '/' : '\\';
644-
_historySavePath = value?.Replace(altPathChar, Path.DirectorySeparatorChar);
641+
_historySavePath = GetUnresolvedProviderPathFromPSPath(value);
645642
}
646643
}
647644
private string _historySavePath;

PSReadLine/History.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Diagnostics;
88
using System.IO;
99
using System.Linq;
10+
using System.Runtime.InteropServices;
1011
using System.Text;
1112
using System.Threading;
1213
using Microsoft.PowerShell.PSReadLine;
@@ -22,20 +23,20 @@ internal class FNV1a32Hash
2223
private const uint FNV32_PRIME = 16777619;
2324
private const uint FNV32_OFFSETBASIS = 2166136261;
2425

25-
internal static uint ComputeHash(byte[] buffer)
26+
internal static uint ComputeHash(string input)
2627
{
2728
uint hash = FNV32_OFFSETBASIS;
28-
for (int i = 0; i < buffer.Length; i++)
29+
for (int i = 0; i < input.Length; i++)
2930
{
30-
hash = (hash ^ buffer[i]) * FNV32_PRIME;
31+
char c = input[i];
32+
uint lowByte = (uint)(c & 0x00FF);
33+
hash = (hash ^ lowByte) * FNV32_PRIME;
34+
35+
uint highByte = (uint)(c >> 8);
36+
hash = (hash ^ highByte) * FNV32_PRIME;
3137
}
3238
return hash;
3339
}
34-
35-
internal static uint ComputeHash(string input)
36-
{
37-
return ComputeHash(Encoding.UTF8.GetBytes(input));
38-
}
3940
}
4041

4142
public partial class PSConsoleReadLine
@@ -171,7 +172,12 @@ private string GetHistorySaveFileMutexName()
171172
{
172173
// Return a reasonably unique name - it's not too important as there will rarely
173174
// be any contention.
174-
return "PSReadLineHistoryFile_" + FNV1a32Hash.ComputeHash(_options.HistorySavePath);
175+
uint hashFromPath = FNV1a32Hash.ComputeHash(
176+
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
177+
? _options.HistorySavePath.ToLower()
178+
: _options.HistorySavePath);
179+
180+
return "PSReadLineHistoryFile_" + hashFromPath.ToString();
175181
}
176182

177183
private void IncrementalHistoryWrite()

0 commit comments

Comments
 (0)