зеркало из https://github.com/mozilla/gecko-dev.git
23277409cf
Normally I believe it's good to keep functionally-distinct code in separate functions when appropriate. However in this case, this `ChunkedJSONWriteFunc::GetTotalLength()` function was only used internally, so it's easy to hide it. It is not very big, so it's less important to keep it separate. And its code (going through all chunks to collect sizes) is similar to the code that follows (going through all chunks to collect their content), so it makes some sense to have these similar things in the same place; if one day this chunking change, both loops would probably have to be modified at the same time. More importantly to justify this change: It was including the final null terminator, which was a bit inconsistent with the usual `Length()` functions in string containers. Now that code is only used where absolutely necessary (before allocating an output buffer), so it rightly accounts for the null terminator that is added at the end of the contents. And in upcoming bug 1612799, `ChunkedJSONWriteFunc` will have a new "retired" state (e.g., after an internal memory allocation failed) in which case a public `GetTotalLength()` function could give misleading results -- should it be 0 (nothing to output), 1 (only the null terminator), 5 ("null"), or the length of some error message? So I think it's better not to expose such an ambiguous function. It could of course be re-introduced if new needs arise in the future. Differential Revision: https://phabricator.services.mozilla.com/D87833 |
||
---|---|---|
.. | ||
android | ||
baseprofiler | ||
build | ||
dllservices | ||
linker | ||
misc | ||
static | ||
tests | ||
moz.build |