fix(core): Fixes type caching & cleanup (#422)
- [X] Fixes some issues with the type caching - [X] Changes type check default to ignore case - [X] Splits out type caching of insensitive and sensitive lists. This means less stuff to iterate through when checking a type against the string. - [X] Adds an ArrayEnumerator, mostly for reference purposes (copy/paste as needed)
This commit is contained in:
parent
b921c38879
commit
e869c105d0
35 changed files with 253 additions and 96 deletions
79
Projects/Server/Collections/ArrayEnumerator.cs
Normal file
79
Projects/Server/Collections/ArrayEnumerator.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: ArrayEnumerator.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Non-thread safe, non-guarded enumerator for classes that have internal arrays.
|
||||
/// Recommended to copy this and use it as a nested struct.
|
||||
/// Recommend adding version checking to properly guard against modification during enumeration.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public struct ArrayEnumerator<T> : IEnumerator<T>
|
||||
{
|
||||
private readonly T[] _array;
|
||||
private int _index;
|
||||
private T? _current;
|
||||
|
||||
public ArrayEnumerator(T[] array)
|
||||
{
|
||||
_array = array;
|
||||
_index = 0;
|
||||
_current = default;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
T[] localList = _array;
|
||||
|
||||
if ((uint)_index < (uint)localList.Length)
|
||||
{
|
||||
_current = _array[_index++];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public T? Current => _current!;
|
||||
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_index == 0 || _index == _array.Length + 1)
|
||||
{
|
||||
throw new InvalidOperationException(nameof(_index));
|
||||
}
|
||||
|
||||
return _current;
|
||||
}
|
||||
}
|
||||
|
||||
void IEnumerator.Reset()
|
||||
{
|
||||
_index = 0;
|
||||
_current = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue