Bug 29631389
When multiple operations are executed at once, they sometimes
cancel each other. For example, if the following transactions
are queued:
Transaction 1: add A
Transaction 2: replace with B
This can be trimmed down to add B.
This CL optimizes fragments in both add and pop directions.
Developers can choose not to allow optimization by
using FragmentTransaction#setAllowOptimization
Test: If6637e9f1c2a414bebaff6404efc45dd828378ad
Change-Id: Iab75be3e0aa388fc79b794e647ac6893165bebd7