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

Add better guard against inserting item from other list into linked list #251

Merged
merged 1 commit into from
Dec 2, 2015

Conversation

bantic
Copy link
Collaborator

@bantic bantic commented Dec 2, 2015

Adds __parent property to items to identify their inclusion in a list.
This allows us to always know when we are inserting an item from another
list. The previous heuristic (checking for presence of next and prev) is
not correct in all scenarios, leading to unusual bugs.

This refactors insertBefore method slightly for clarity, and
simplifies remove because we now know for sure when we are removing
an item in this list.

Adds some additional test coverage.

if (this._adoptItem) { this._adoptItem(item); }
}
freeItem(item) {
item[PARENT_PROP] = null;
item.prev = null;
item.next = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this already be done by remove?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you've moved it. As prev and next are related to position and not ownerships (adopt/free) IMO the changes should be made in remove. For example adopt does not set a prev or next.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I've moved it. Thanks for looking it over.

@mixonic
Copy link
Contributor

mixonic commented Dec 2, 2015

👍

Adds `__parent` property to items to identify their inclusion in a list.
This allows us to always know when we are inserting an item from another
list. The previous heuristic (checking for presence of `next` and `prev`) is
not correct in all scenarios, leading to unusual bugs.

This refactors `insertBefore` method slightly for clarity, and
simplifies `remove` because we now know for sure when we are removing
an item in this list.

Adds some additional test coverage.
bantic added a commit that referenced this pull request Dec 2, 2015
Add better guard against inserting item from other list into linked list
@bantic bantic merged commit e0013dd into master Dec 2, 2015
@bantic bantic deleted the ll-refactor branch December 2, 2015 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants