7
7
using System . Diagnostics ;
8
8
using System . IO ;
9
9
using System . Linq ;
10
+ using System . Runtime . InteropServices ;
10
11
using System . Text ;
11
12
using System . Threading ;
12
13
using Microsoft . PowerShell . PSReadLine ;
@@ -22,20 +23,20 @@ internal class FNV1a32Hash
22
23
private const uint FNV32_PRIME = 16777619 ;
23
24
private const uint FNV32_OFFSETBASIS = 2166136261 ;
24
25
25
- internal static uint ComputeHash ( byte [ ] buffer )
26
+ internal static uint ComputeHash ( string input )
26
27
{
27
28
uint hash = FNV32_OFFSETBASIS ;
28
- for ( int i = 0 ; i < buffer . Length ; i ++ )
29
+ for ( int i = 0 ; i < input . Length ; i ++ )
29
30
{
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 ;
31
37
}
32
38
return hash ;
33
39
}
34
-
35
- internal static uint ComputeHash ( string input )
36
- {
37
- return ComputeHash ( Encoding . UTF8 . GetBytes ( input ) ) ;
38
- }
39
40
}
40
41
41
42
public partial class PSConsoleReadLine
@@ -171,7 +172,12 @@ private string GetHistorySaveFileMutexName()
171
172
{
172
173
// Return a reasonably unique name - it's not too important as there will rarely
173
174
// 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 ( ) ;
175
181
}
176
182
177
183
private void IncrementalHistoryWrite ( )
0 commit comments