From 0f716e3ac4d8af67fed7c23994d2c0f53d8eb2ae Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Sun, 4 May 2008 00:06:34 +0000 Subject: * Simplify CreateFolder() by folding previous special root case into FindFolder() --- .../Communications/Cache/InventoryFolderImpl.cs | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs') diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs index af05af3..c8cec69 100644 --- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs @@ -69,7 +69,7 @@ namespace OpenSim.Framework.Communications.Cache /// /// /// The newly created subfolder. Returns null if the folder already exists - public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) + public InventoryFolderImpl CreateChildFolder(LLUUID folderID, string folderName, ushort type) { lock (SubFolders) { @@ -82,6 +82,7 @@ namespace OpenSim.Framework.Communications.Cache subFold.ParentID = this.ID; subFold.Owner = Owner; SubFolders.Add(subFold.ID, subFold); + return subFold; } } @@ -135,7 +136,7 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// Delete an item from the folder. + /// Deletes an item if it exists in this folder or any children /// /// /// @@ -157,6 +158,7 @@ namespace OpenSim.Framework.Communications.Cache foreach (InventoryFolderImpl folder in SubFolders.Values) { found = folder.DeleteItem(itemID); + if (found == true) { break; @@ -168,37 +170,35 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// Returns the folder requested if it exists as a descendent of this folder + /// Returns the folder requested if it is this folder or is a descendent of this folder. The search is depth + /// first. /// /// The requested folder if it exists, null if it does not. public InventoryFolderImpl FindFolder(LLUUID folderID) { - InventoryFolderImpl returnFolder = null; + if (folderID == ID) + { + return this; + } lock (SubFolders) { - if (SubFolders.ContainsKey(folderID)) - { - returnFolder = SubFolders[folderID]; - } - else + foreach (InventoryFolderImpl folder in SubFolders.Values) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + InventoryFolderImpl returnFolder = folder.FindFolder(folderID); + + if (returnFolder != null) { - returnFolder = folder.FindFolder(folderID); - if (returnFolder != null) - { - break; - } + return returnFolder; } } } - return returnFolder; + return null; } /// - /// Return the list of items in this folder + /// Return the list of child items in this folder /// public List RequestListOfItems() { -- cgit v1.1