Skip to content

Commit

Permalink
Merge pull request #217 from shangfengh/dev
Browse files Browse the repository at this point in the history
chore(SafeValue): 🔒 fix some warnings
  • Loading branch information
shangfengh authored Apr 13, 2024
2 parents 62747be + fbae832 commit 92c8cf6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion logic/Preparation/Utility/Value/SafeValue/AtomicInt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public IIntAddable Score
{
get
{
return Interlocked.CompareExchange(ref score, null, null);
return Interlocked.CompareExchange(ref score!, null, null);
}
set
{
Expand Down
86 changes: 49 additions & 37 deletions logic/Preparation/Utility/Value/SafeValue/ObjPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class ObjPool<T, TType>(Func<T, TType> classfier,

#region 属性

/// <summary>
/// 包含列表中为null的元素
/// </summary>
public int Size
{
get
Expand All @@ -36,6 +39,9 @@ public int Size
}
}
}
/// <summary>
/// 列表中有null的元素亦不认为空
/// </summary>
public bool IsEmpty
{
get
Expand Down Expand Up @@ -163,9 +169,10 @@ public List<TResult> Travel<TResult>(Func<T, TResult> func)
{
var len = ls.Count;
for (int i = 0; i < len; i++)
{
ret.Add(func(ls[i]));
}
if (ls[i] != null)
{
ret.Add(func(ls[i]!));
}
}
}
return ret;
Expand All @@ -178,9 +185,7 @@ public void Travel(Action<T> func)
{
var len = ls.Count;
for (int i = 0; i < len; i++)
{
func(ls[i]);
}
if (ls[i] != null) func(ls[i]!);
}
}
}
Expand All @@ -192,9 +197,10 @@ public void Travel(Action<T> func)
lock (dictLock)
{
for (int i = 0; i < len; i++)
{
ret.Add(func(ls[i]));
}
if (ls[i] != null)
{
ret.Add(func(ls[i]!));
}
}
return ret;
}
Expand All @@ -206,7 +212,7 @@ public void Travel(TType tp, Action<T> func)
{
for (int i = 0; i < len; i++)
{
func(ls[i]);
if (ls[i] != null) func(ls[i]!);
}
}
}
Expand All @@ -223,9 +229,10 @@ public void Travel(TType tp, Action<T> func)
{
var len = ls.Count;
for (int i = 0; i < len; i++)
{
if (cond(ls[i])) return ls[i];
}
if (ls[i] != null)
{
if (cond(ls[i]!)) return ls[i];
}
}
}
return null;
Expand All @@ -237,9 +244,10 @@ public void Travel(TType tp, Action<T> func)
lock (dictLock)
{
for (int i = 0; i < len; i++)
{
if (cond(ls[i])) return ls[i];
}
if (ls[i] != null)
{
if (cond(ls[i]!)) return ls[i];
}
}
return null;
}
Expand All @@ -259,15 +267,16 @@ public void Travel(TType tp, Action<T> func)
{
var len = ls.Count;
for (int i = 0; i < len; i++)
{
ret.Add(func(ls[i]));
if (cond(ls[i]))
if (ls[i] != null)
{
retObj = ls[i];
flag = true;
break;
ret.Add(func(ls[i]!));
if (cond(ls[i]!))
{
retObj = ls[i];
flag = true;
break;
}
}
}
if (flag) break;
}
}
Expand All @@ -281,10 +290,11 @@ public void Travel(TType tp, Action<T> func)
{
var len = ls.Count;
for (int i = 0; i < len; i++)
{
func(ls[i]);
if (cond(ls[i])) return ls[i];
}
if (ls[i] != null)
{
func(ls[i]!);
if (cond(ls[i]!)) return ls[i];
}
}
}
return null;
Expand All @@ -298,14 +308,15 @@ public void Travel(TType tp, Action<T> func)
lock (dictLock)
{
for (int i = 0; i < len; i++)
{
ret.Add(func(ls[i]));
if (cond(ls[i]))
if (ls[i] != null)
{
retObj = ls[i];
break;
ret.Add(func(ls[i]!));
if (cond(ls[i]!))
{
retObj = ls[i];
break;
}
}
}
}
return (ret, retObj);
}
Expand All @@ -316,10 +327,11 @@ public void Travel(TType tp, Action<T> func)
lock (dictLock)
{
for (int i = 0; i < len; i++)
{
func(ls[i]);
if (cond(ls[i])) return ls[i];
}
if (ls[i] != null)
{
func(ls[i]!);
if (cond(ls[i]!)) return ls[i];
}
}
return null;
}
Expand Down

0 comments on commit 92c8cf6

Please sign in to comment.