[ITLib] Get a the playlists tree

Hi,

Following my artists / albums / tracks tree, I decided to redo my playlists tree which was working but was a quite slow and complicated.

So I have that recursive func now :

let lib = try ITLibrary(apiVersion: "1.1")
let theITPlaylists = lib.allPlaylists
let theRootITPlaylists = theITPlaylists.filter({ $0.parentID == nil })
let thePlaylistsTree = getPlaylistsTree(theLevelITPlaylists: theRootITPlaylists, theITPlaylists: theITPlaylists)

func getPlaylistsTree(theLevelITPlaylists: [ITLibPlaylist], theITPlaylists: [ITLibPlaylist]) -> [Playlist] {
        var thePlaylistsTree = [Playlist]()
        for theITPlaylist in theLevelITPlaylists {
            let thePlaylist = Playlist(thePlaylist: theITPlaylist) // a NSObject with the isLeaf bool and children array to show the tree in a NSOutlineView
            if theITPlaylist.kind == .folder {
                let theChildrenPlaylists = theITPlaylists.filter({ $0.parentID == theITPlaylist.persistentID })
                thePlaylist.children = getPlaylistsTree(theLevelITPlaylists: theChildrenPlaylists, theITPlaylists: theITPlaylists)
            }
            thePlaylistsTree.append(thePlaylist)
        }
        return thePlaylistsTree
    }

Very simple.

But I think I can improve it more by deleting the playlists in the theITPlaylists array once it is added in the tree. Like that, the filter to search for the children's playlist folder could be more efficient :

let theChildrenITPlaylists = theITPlaylists.filter({ $0.parentID == theFolderITPlaylist.persistentID })

Instead of filtering all the playlists, I just filter the remaining playlists, right ?

But is it faster or whatever the array.count is, it still the same ?

How can I do that ?

Thx.