I'm not afraid of 1 superfluous removeChild ;)

To know what Gecko is doing for childElementCount, the best is to read Gecko's code !
http://dxr.mozilla.org/mozilla-central/source/content/base/public/FragmentOrElement.h#227

I tried to follow the code but I couldn't find exactly what it was doing, you can try ;)