diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-04-09 09:09:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-04-09 09:09:12 +0300 |
commit | c800ee6bfe602d1cdfafc042228add3692bdb12e (patch) | |
tree | a02dad89cb052cdd388791509696e6bbf94cf2ae /source/blender/blenlib/intern | |
parent | 79e862ad6b416968f3e0afa7a18f98ab11a4db03 (diff) | |
parent | 162e184ffd0f2e5f1584b95339df6cb3c429f017 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 3bf0dfa09fa..abc4a773328 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -370,6 +370,40 @@ void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) } } + +/** + * Insert a link in place of another, without changing it's position in the list. + * + * Puts `vnewlink` in the position of `vreplacelink`, removing `vreplacelink`. + * - `vreplacelink` *must* be in the list. + * - `vnewlink` *must not* be in the list. + */ +void BLI_insertlinkreplace(ListBase *listbase, void *vreplacelink, void *vnewlink) +{ + Link *l_old = vreplacelink; + Link *l_new = vnewlink; + + /* update adjacent links */ + if (l_old->next != NULL) { + l_old->next->prev = l_new; + } + if (l_old->prev != NULL) { + l_old->prev->next = l_new; + } + + /* set direct links */ + l_new->next = l_old->next; + l_new->prev = l_old->prev; + + /* update list */ + if (listbase->first == l_old) { + listbase->first = l_new; + } + if (listbase->last == l_old) { + listbase->last = l_new; + } +} + /** * Reinsert \a vlink relative to its current position but offset by \a step. Doesn't move * item if new position would exceed list (could optionally move to head/tail). |