But the question was really not about this, but rather if it makes any sense to do a mini-hashing of the sizes instead of static padding, for making the preimage more mutable when you redistribute bytes between the stack elements?
The “original” variant:
const HashWriter HASHER_PAIRCOMMIT{TaggedHash("PairCommit")};
uint256 PairCommitHash(const std::vector<unsigned char>& x1, const std::vector<unsigned char>& x2)
{
// PAD is 0x00000001 in little endian serializaton
const uint32_t PAD = 0x01000000;
HashWriter ss{HASHER_PAIRCOMMIT};
ss << x1
<< x2
<< uint32_t(x1.size()) << PAD
<< uint32_t(x2.size()) << PAD;
return ss.GetSHA256();
}