diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-10-02 06:52:44 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-10-02 06:52:44 +0200 |
| commit | b95beb4597dec47fee3a3d3134eea138e72d27a8 (patch) | |
| tree | 158bf24abbbbcff703613168ed52863d50d390d3 /kernel/kapi/filesystem.tests.cpp | |
| parent | 9a01bef5542b26f13467d2fc6fde935d6301a98b (diff) | |
| download | kernel-b95beb4597dec47fee3a3d3134eea138e72d27a8.tar.xz kernel-b95beb4597dec47fee3a3d3134eea138e72d27a8.zip | |
kstd: ring_buffer: clear moved-from buffer
While the standard says that a move-from object is in a valid but
unspecified state, thus making it legal to leave the moved-from buffer
in a non-empty state, we can do better here. For one, standard
containers generally leave the moved-from object in an empty state.
Secondly, destroying the contents of a ring_buffer object has linear
complexity, as does moving the contents of a ring_buffer object. We can
therefore clear the moved-from object while we are moving from it,
without increasing the complexity of the move operation. At the same
time, we can thereby reduce the amount of work that needs to be done
when the moved-from object is finally destroyed.
Note that during the move assignment operation, the moved-from buffer is
in a somewhat peculiar state. Some of its elements have been destroyed,
but its size has not changed. This is okay, because we are essentially
still executing a transition from one valid state into another once. At
the end of the move operation, we ensure that the size of the moved-from
buffer is set to zero, thus reestablishing its invariant.
Diffstat (limited to 'kernel/kapi/filesystem.tests.cpp')
0 files changed, 0 insertions, 0 deletions
