88using System . IO ;
99using System . Linq ;
1010using System . Management . Automation ;
11+ using System . Runtime . InteropServices ;
1112using System . Text ;
1213using System . Text . RegularExpressions ;
1314using System . Threading ;
@@ -24,20 +25,20 @@ internal class FNV1a32Hash
2425 private const uint FNV32_PRIME = 16777619 ;
2526 private const uint FNV32_OFFSETBASIS = 2166136261 ;
2627
27- internal static uint ComputeHash ( byte [ ] buffer )
28+ internal static uint ComputeHash ( string input )
2829 {
2930 uint hash = FNV32_OFFSETBASIS ;
30- for ( int i = 0 ; i < buffer . Length ; i ++ )
31+ for ( int i = 0 ; i < input . Length ; i ++ )
3132 {
32- hash = ( hash ^ buffer [ i ] ) * FNV32_PRIME ;
33+ char c = input [ i ] ;
34+ uint lowByte = ( uint ) ( c & 0x00FF ) ;
35+ hash = ( hash ^ lowByte ) * FNV32_PRIME ;
36+
37+ uint highByte = ( uint ) ( c >> 8 ) ;
38+ hash = ( hash ^ highByte ) * FNV32_PRIME ;
3339 }
3440 return hash ;
3541 }
36-
37- internal static uint ComputeHash ( string input )
38- {
39- return ComputeHash ( Encoding . UTF8 . GetBytes ( input ) ) ;
40- }
4142 }
4243
4344 public partial class PSConsoleReadLine
@@ -207,7 +208,12 @@ private string GetHistorySaveFileMutexName()
207208 {
208209 // Return a reasonably unique name - it's not too important as there will rarely
209210 // be any contention.
210- return "PSReadLineHistoryFile_" + FNV1a32Hash . ComputeHash ( _options . HistorySavePath ) ;
211+ uint hashFromPath = FNV1a32Hash . ComputeHash (
212+ RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
213+ ? _options . HistorySavePath . ToLower ( )
214+ : _options . HistorySavePath ) ;
215+
216+ return "PSReadLineHistoryFile_" + hashFromPath . ToString ( ) ;
211217 }
212218
213219 private void IncrementalHistoryWrite ( )
0 commit comments