In Mathematica everything is specified via patterns. So are, of course, Piecewise functions. To obtain a standardized form for nested Piecewise functions you were right to apply PiecewiseExpand first. So let's take a look at an example of a nested Piecewise function:
(*definition*)
pw = Piecewise[{{g[x],x > 5}, {Piecewise[{{h1[x],x < 1},
{h2[x],x > 2}}, h3[x]], x < 3}}, f[x]];
(*expansion*)
pwe = PiecewiseExpand[pw];
Remember my remark about patterns before. Let's take a look at the underlying pattern (form) of the expanded Piecewise function:
pwe // FullForm
This gives you a clue on how to extract all the functions via using the Part operator, here is one possibility to do it:
Flatten[{pwe[[1, ;; , 1]], pwe[[2]]}]
{f[x], g[x], h1[x], h2[x], h3[x]}
Have fun playing around with this.
Unionshould be slower because it creates a new object, whileFlattendoes not do that. Also important to note is that according to Mathematica helpUnion"gives a sorted list of all the distinct elements", so additional sorting is applied, which costs time. For lists containing only a few elements you should not really notice a difference, of course this looks different for large lists. – Wizard Sep 17 '16 at 14:28