Better code design trick copied from git/alloc.c.