diff --git a/OpenSim/Region/Framework/Scenes/LinksetData.cs b/OpenSim/Region/Framework/Scenes/LinksetData.cs index 476c6941770..9fade411361 100644 --- a/OpenSim/Region/Framework/Scenes/LinksetData.cs +++ b/OpenSim/Region/Framework/Scenes/LinksetData.cs @@ -44,9 +44,9 @@ public int AddOrUpdateLinksetDataKey(string key, string value, string pass) return 1; LinksetDataEntry entry = null; - if (Data.TryGetValue(key, out entry) == true) + if (Data.TryGetValue(key, out entry)) { - if (entry.CheckPassword(pass) == false) + if (!entry.CheckPassword(pass)) return -1; if (entry.Value == value) @@ -85,10 +85,10 @@ public int DeleteLinksetDataKey(string key, string pass) return -1; LinksetDataEntry entry; - if (Data.TryGetValue(key, out entry) == false) + if (!Data.TryGetValue(key, out entry)) return -1; - if (entry.CheckPassword(pass) == false) + if (!entry.CheckPassword(pass)) return 1; Data.Remove(key); @@ -234,6 +234,7 @@ public bool LinksetDataOverLimit() { return (LinksetDataBytesFree < 0); } + /// /// Merge the linksetData present in another Linkset into this one. /// The current root will have the new linkset for the merged sog. @@ -242,18 +243,13 @@ public bool LinksetDataOverLimit() /// public void MergeLinksetData(LinksetData otherLinksetData) { + // Nothing to merge? if (otherLinksetData == null) return; lock (linksetDataLock) { - var values = otherLinksetData.Data.ToArray(); - - otherLinksetData.Data.Clear(); - otherLinksetData.LinksetDataBytesFree = 0; - otherLinksetData.LinksetDataBytesUsed = LINKSETDATA_MAX; - - foreach (var kvp in values) + foreach (var kvp in otherLinksetData.Data) { // If its already present skip it if (Data.ContainsKey(kvp.Key)) @@ -263,10 +259,15 @@ public void MergeLinksetData(LinksetData otherLinksetData) if (LinksetDataOverLimit()) break; - // Do we send events? - Data.Add(kvp.Key, kvp.Value); - LinksetDataAccountingDelta(kvp.Value.GetCost(kvp.Key)); + var value = new LinksetDataEntry(kvp.Value.Value, kvp.Value.Password); + Data.Add(kvp.Key, value); + LinksetDataAccountingDelta(value.GetCost(kvp.Key)); } + + // Clear the LinksetData entries from the "other" SOG + otherLinksetData.Data.Clear(); + otherLinksetData.LinksetDataBytesFree = 0; + otherLinksetData.LinksetDataBytesUsed = LINKSETDATA_MAX; } } @@ -281,12 +282,12 @@ public string ReadLinksetData(string key, string pass) lock (linksetDataLock) { if (Data.Count <= 0) - { - LinksetDataEntry entry; - if (Data.TryGetValue(key, out entry) == true) - return entry.CheckPasswordAndGetValue(pass); - return string.Empty; + + LinksetDataEntry entry; + if (Data.TryGetValue(key, out entry)) + { + return entry.CheckPasswordAndGetValue(pass); } return string.Empty; @@ -349,18 +350,12 @@ public bool CheckPassword(string pass) { // A undocumented caveat for LinksetData appears to be that even for unprotected values, // if a pass is provided, it is still treated as protected - if (this.Password == pass) - return true; - else - return false; + return this.Password == pass ? true : false; } public string CheckPasswordAndGetValue(string pass) { - if (string.IsNullOrEmpty(this.Password) || (this.Password == pass)) - return this.Value; - else - return string.Empty; + return (string.IsNullOrEmpty(this.Password) || (this.Password == pass)) ? this.Value : string.Empty; } /// @@ -376,7 +371,7 @@ public int GetCost(string key) cost += Encoding.UTF8.GetBytes(key).Length; cost += Encoding.UTF8.GetBytes(this.Value).Length; - if (string.IsNullOrEmpty(this.Password) == false) + if (!string.IsNullOrEmpty(this.Password)) { // For parity, the pass adds 32 bytes regardless of the length. See LL caveats cost += Math.Max(Encoding.UTF8.GetBytes(this.Password).Length, 32); @@ -387,7 +382,7 @@ public int GetCost(string key) public bool IsProtected() { - return (string.IsNullOrEmpty(this.Password) == false); + return !string.IsNullOrEmpty(Password); } } } \ No newline at end of file