code clean up
This commit is contained in:
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="StringHashMultiplexer.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="StringHashMultiplexer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -50,47 +47,47 @@ namespace StgSharp.Collections
|
||||
set => _initCount = value;
|
||||
}
|
||||
|
||||
public void CacheHash( string obj, int count )
|
||||
public void CacheHash(string obj, int count)
|
||||
{
|
||||
_hashCache = ForceComputeHash( obj );
|
||||
_hashCache = ForceComputeHash(obj);
|
||||
_initCount = count;
|
||||
_remainedCount = _initCount;
|
||||
_source = obj;
|
||||
}
|
||||
|
||||
public bool Equals( string x, string y )
|
||||
public bool Equals(string x, string y)
|
||||
{
|
||||
return x == y;
|
||||
}
|
||||
|
||||
public void ExtendCache( int count )
|
||||
public void ExtendCache(int count)
|
||||
{
|
||||
_initCount += count;
|
||||
_remainedCount += count;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe int ForceComputeHash( [NotNull] string obj )
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe int ForceComputeHash([NotNull] string obj)
|
||||
{
|
||||
int hash;
|
||||
fixed( char* cPtr = obj.AsSpan() ) {
|
||||
hash = InternalIO.Intrinsic.city_hash_simplify( cPtr, obj.Length );
|
||||
fixed (char* cPtr = obj.AsSpan()) {
|
||||
hash = InternalIO.Intrinsic.city_hash_simplify(cPtr, obj.Length);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public int GetHashCode( string obj )
|
||||
public int GetHashCode(string obj)
|
||||
{
|
||||
if( _remainedCount > 0 && ReferenceEquals( _source, obj ) )
|
||||
if (_remainedCount > 0 && ReferenceEquals(_source, obj))
|
||||
{
|
||||
_remainedCount--;
|
||||
return _hashCache;
|
||||
}
|
||||
if( ReferenceEquals( _sourceLast, obj ) ) {
|
||||
if (ReferenceEquals(_sourceLast, obj)) {
|
||||
return _hashLast;
|
||||
}
|
||||
_sourceLast = obj;
|
||||
_hashLast = ForceComputeHash( obj );
|
||||
_hashLast = ForceComputeHash(obj);
|
||||
return _hashLast;
|
||||
}
|
||||
|
||||
@@ -101,7 +98,7 @@ namespace StgSharp.Collections
|
||||
|
||||
private bool disposedValue;
|
||||
private readonly ThreadLocal<StringHashMultiplexer> _multiplexers =
|
||||
new( () => new StringHashMultiplexer() );
|
||||
new(() => new StringHashMultiplexer());
|
||||
|
||||
public int RemainedMultiplexCount
|
||||
{
|
||||
@@ -109,51 +106,51 @@ namespace StgSharp.Collections
|
||||
set => _multiplexers.Value.RemainedMultiplexCount = value;
|
||||
}
|
||||
|
||||
public void CacheHash( string obj, int count )
|
||||
public void CacheHash(string obj, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// ~ConcurrentStringHashMultiplexer()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose( disposing: true );
|
||||
GC.SuppressFinalize( this );
|
||||
Dispose(disposing:true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public bool Equals( string x, string y )
|
||||
public bool Equals(string x, string y)
|
||||
{
|
||||
return x == y;
|
||||
}
|
||||
|
||||
public void ExtendCache( int count )
|
||||
public void ExtendCache(int count)
|
||||
{
|
||||
_multiplexers.Value.ExtendCache( count );
|
||||
_multiplexers.Value.ExtendCache(count);
|
||||
}
|
||||
|
||||
public unsafe int ForceComputeHash( [NotNull] string obj )
|
||||
public unsafe int ForceComputeHash([NotNull] string obj)
|
||||
{
|
||||
int hash;
|
||||
fixed( char* cPtr = obj.AsSpan() ) {
|
||||
hash = InternalIO.Intrinsic.city_hash_simplify( cPtr, obj.Length );
|
||||
fixed (char* cPtr = obj.AsSpan()) {
|
||||
hash = InternalIO.Intrinsic.city_hash_simplify(cPtr, obj.Length);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public int GetHashCode( string obj )
|
||||
public int GetHashCode(string obj)
|
||||
{
|
||||
return _multiplexers.Value.GetHashCode( obj );
|
||||
return _multiplexers.Value.GetHashCode(obj);
|
||||
}
|
||||
|
||||
private void Dispose( bool disposing )
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if( !disposedValue )
|
||||
if (!disposedValue)
|
||||
{
|
||||
if( disposing ) {
|
||||
if (disposing) {
|
||||
_multiplexers.Dispose();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user