Make pack object lookup use loops

We currently have three-function cycle which keeps calling each other until we find a base. This is not ideal, as it means that we have unbounded stack growth.

Instead, let's use a couple of loops. One to find out what objects we need and another to apply the deltas. This also makes it IMO somewhat more readable.

Don't merge yet, as this still doesn't make use of the delta base cache, so it's quite a bit slower than the implementation we have in dev.