Skip to content
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

Deque.insert() should not use Deque.swap() directly #43

Closed
samchon opened this issue Jul 24, 2019 · 0 comments
Closed

Deque.insert() should not use Deque.swap() directly #43

samchon opened this issue Jul 24, 2019 · 0 comments
Assignees
Labels
enhancement New feature or request
Projects

Comments

@samchon
Copy link
Owner

samchon commented Jul 24, 2019

Summary

  • TSTL Version: 2.2.1
  • Expected behavior: Deque.insert() does not call Deque.swap()
  • Actual behavior: Deque.insert() calls the Deque.swap()

Code occuring the bug

tstl/src/container/Deque.ts

Lines 457 to 463 in 816b9ea

// INSERT ITEM SEQUENTIALLY
deque._Insert_to_end(this.begin(), pos);
deque._Insert_to_end(first, last);
deque._Insert_to_end(pos, this.end());
// AND SWAP THIS WITH THE TEMP
this.swap(deque);

Detailed Story

ECol extends TSTL containers and dispatches CollectionEvents. The CollectionEvents are dispatched when its container's elements are inserted, erased or changed. Detailed types of those CollectionEvents are:

Type Means Dispatched By
"insert" Elements are inserted Container.insert()
"erase" Elements are erased Container.erase()
"refresh" Elements are changed Container.swap(), Iterator.set, ...

In ECol, DequeCollection extends Deque to dispatch CollectionEvents. As you can see from the above, DequeCollection.swap() dispatches "refresh" typed CollectionEvent. If Deque.insert() keeps using Deque.swap(), DequeCollection.insert() will dispatch not only "insert", but also "refresh" typed CollectionEvent, which is not valid.

To avoid the bad situation, Deque.insert() should not call Deque.swap() directly.

@samchon samchon added bug Something isn't working enhancement New feature or request labels Jul 24, 2019
@samchon samchon self-assigned this Jul 24, 2019
@samchon samchon added this to To do in v2.2 Update via automation Jul 24, 2019
samchon pushed a commit that referenced this issue Jul 24, 2019
@samchon samchon moved this from To do to In progress in v2.2 Update Jul 24, 2019
samchon pushed a commit that referenced this issue Jul 28, 2019
@samchon samchon closed this as completed Jul 28, 2019
v2.2 Update automation moved this from In progress to Done Jul 28, 2019
@samchon samchon moved this from Done to Patch in v2.2 Update Jul 28, 2019
@samchon samchon removed the bug Something isn't working label Jul 28, 2019
@samchon samchon reopened this Nov 10, 2019
v2.2 Update automation moved this from Patch to In progress Nov 10, 2019
@samchon samchon closed this as completed Nov 10, 2019
v2.2 Update automation moved this from In progress to Done Nov 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
v2.2 Update
  
Done
Development

No branches or pull requests

1 participant