removeUnreferencedElements: Remove defs before unref elements
removeUnreferencedElements: Remove defs before unref elements

The `removeUnusedDefs` function can take `referencedIDs` as parameter
and its work do not invalidate it.  By moving it up in
`removeUnreferencedElements` we can save a call to
`findReferencedElements` per call to `removeUnreferencedElements`.

Signed-off-by: Niels Thykier <a802a5730c0da02a06106670cc12c7838c6e90dc@thykier.net>

oberstet/scour,Ede123/scour,scour-project/scour,codedread/scour