dot-switch_reference_if_needed function

Check if reference switching is necessary