FWIW this is the only only inner loop which isn't completely in C yet (due to the access to `flat_entity_dofs`).