-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CompositeCloseable: prepend doesn't respect ordering #2097
CompositeCloseable: prepend doesn't respect ordering #2097
Conversation
Motivation: `DefaultCompositeCloseable` does not respect ordering if `prepend` operation is invoked after `append`. Modifications: - Change `Operand.closables` to `ArrayDeque`; - Use `addFirst` for `prepend` operation; - Test ordiring for "prepend after append" and "prepend after merge"; Result: Correct ordering of invoking `AsyncCloseable`s if `prepend` is used after `append`.
@@ -203,8 +202,8 @@ private Completable buildCompletable(Function<AsyncCloseable, Completable> close | |||
} | |||
|
|||
private static final class Operand { | |||
private final List<AsyncCloseable> closables = new ArrayList<>(4); | |||
private final boolean isMerge; | |||
final Deque<AsyncCloseable> closables = new ArrayDeque<>(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default size of the collection changes. There is probably no reason not to still use 4 as that still typically fits within the alignment size of a heap allocation of a reference array. ie. The first resize to 4 will probably just reallocate to another array with less wasted space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
Motivation: `DefaultCompositeCloseable` does not respect ordering if `prepend` operation is invoked after `append`. Modifications: - Change `Operand.closables` to `ArrayDeque`; - Use `addFirst` for `prepend` operation; - Test ordiring for "prepend after append" and "prepend after merge"; Result: Correct ordering of invoking `AsyncCloseable`s if `prepend` is used after `append`.
Motivation:
DefaultCompositeCloseable
does not respect ordering ifprepend
operation is invoked after
append
. It causes issues when the orderingmatters for closeable resources that depend upon each other.
Modifications:
Operand.closables
toArrayDeque
;addFirst
forprepend
operation;Result:
Correct ordering of invoking
AsyncCloseable
s ifprepend
is usedafter
append
.