Skip to content

Commit

Permalink
Rewrite null checks for older dot net
Browse files Browse the repository at this point in the history
  • Loading branch information
zontreck committed Nov 6, 2023
1 parent f42a8eb commit 1b4a6f7
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5890,7 +5890,8 @@ public int AddOrUpdateLinksetDataKey(string key, string value, string pass)
{
lock (linksetDataLock)
{
LinksetData = LinksetData ?? new Dictionary<string, ProtectedData>();
if (LinksetData == null) LinksetData = new Dictionary<string, ProtectedData>();

ProtectedData original = LinksetData.ContainsKey(key) ? LinksetData[key] : null;
ProtectedData pd = null;

Expand Down Expand Up @@ -5933,13 +5934,11 @@ public string ReadLinksetData(string name, string pass)
{
lock (linksetDataLock)
{

ProtectedData original = LinksetData?[name] ?? null;
if (original != null)
{
return original.testAndGetValue(pass);
}
else return "";
if (LinksetData == null) return "";
ProtectedData orig;
var success = LinksetData.TryGetValue(name, out orig);
if (!success) return "";
else return orig.testAndGetValue(pass);
}
}

Expand All @@ -5953,25 +5952,23 @@ public int DeleteLinksetDataKey(string key, string pass)
{
lock (linksetDataLock)
{
LinksetData = LinksetData ?? new Dictionary<string, ProtectedData>();
ProtectedData origin = LinksetData?[key] ?? null;
if (origin == null)
if (LinksetData == null) LinksetData = new Dictionary<string, ProtectedData>();
ProtectedData origin;
var success = LinksetData.TryGetValue(key, out origin);

if (!success) return -1;

if (origin.test(pass))
{
return -1;
LinksetData.Remove(key);
updateLinksetDataAccounting();
return 0;
}
else
{
if (origin.test(pass))
{
LinksetData?.Remove(key);
updateLinksetDataAccounting();
return 0;
}
else
{
return 1;
}
return 1;
}

}
}

Expand All @@ -5980,7 +5977,8 @@ public string[] GetLinksetDataSubList(int start, int count)
lock (linksetDataLock)
{
if (count == -1) count = LinksetDataKeys;
LinksetData = LinksetData ?? new Dictionary<string, ProtectedData>();
if (LinksetData == null) LinksetData = new Dictionary<string, ProtectedData>();

List<string> ret = new List<string>();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
ret
is useless, since its value is never read.
ret = LinksetData.Keys.Skip(start).Take(count).ToList();
return ret.ToArray();
Expand All @@ -5991,7 +5989,7 @@ public void ResetLinksetData()
{
lock (linksetDataLock)
{
LinksetData = LinksetData ?? new Dictionary<string, ProtectedData>();
if (LinksetData == null) LinksetData = new Dictionary<string, ProtectedData>();
LinksetData.Clear();
}

Expand Down Expand Up @@ -6020,19 +6018,21 @@ public void updateLinksetDataAccounting()
}

linksetDataBytesUsed = ms.ToArray().Length;
linksetDataBytesFree = 131072 - linksetDataBytesUsed;
linksetDataBytesFree = LINKSETDATA_MAX - linksetDataBytesUsed;
}
}
}

public const int LINKSETDATA_MAX = 131072; // 128 KB
public int linksetDataBytesUsed;
public int linksetDataBytesFree = 131072; // Default
public int linksetDataBytesFree = LINKSETDATA_MAX; // Default

public bool HasLinksetData
{
get
{
return LinksetData?.Count > 0;
if (LinksetData == null) return false;
return LinksetData.Count > 0;
}
}

Expand All @@ -6048,7 +6048,8 @@ public int LinksetDataKeys
{
get
{
return LinksetData?.Count ?? 0;
if (LinksetData == null) return 0;
return LinksetData.Count;
}
}

Expand Down

0 comments on commit 1b4a6f7

Please sign in to comment.