Pavel Roskin on the upstream ML made a more elegant version of the above check, which I have included in this new version of the patch.
Pavel Roskin on the upstream ML made a more elegant version of the above check, which I have included in this new version of the patch.