Improve the performance of isRoot() to constant time