Interleave the code for narrow and wide character streams. This makes it more obvious that the two pieces of code are identical. Furthermore, it makes it easier to conditionally compile support for certain streams, as less #ifdef blocks are needed.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
I'm going to have to defer to @mclow.lists on this one... I'm not sure whether the state_types have to be contiguous or not.
I just looked through include/__std_stream and it doesn't seem to be the case that they need to be contiguous.
The address of the mbstate_t is stored in the __st_ member. A reference to it gets passed on to codecvt objects. The codecvt code in src/locale.cpp passes on the addresses to wcrtomb_l() and friends. It looks like we never do any pointer arithmetic on them.
How about we do this in two steps:
- Move the code around w/o any functionality change.
[ i.e, Interleave the code for narrow and wide character streams. This makes it more obvious that the two pieces of code are identical. ]
- Get rid (maybe) of the mbstates array - though I don't really see the motivation for that.
The reason why I removed the array and replaced it by separate mbstates is that once the change for making std::cin and std::cout optional hits the tree, the array will only be used partially. You could add some #ifdefs to reduce the size of the array and use different indexing based on whether std::cin/std::cout should be present, but that makes things even worse.
Let me split this change up even further.