[sgen] Improve fix for BXC#14834 to avoid redundant code