Only iterate each parent once

Also tidy some warnings.

b/10893667

Change-Id: I207cf2b4c26bd3b8c695971bcde6254236a54c57
2 files changed