diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-11-16 16:02:18 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-11-16 16:06:03 +0300 |
commit | 0e60accf2afa4fc69da99743bb64d82cb3e0fbc4 (patch) | |
tree | 7013c96248c881481287eb84f8de715f1f0563f2 /source/blender/blenlib/intern/listbase.c | |
parent | 7d040d2a088ec425550da4242650f1ff75680e0d (diff) |
BLI_listbase: Add BLI_listbase_count_ex (sets a limit)
This can be used to avoid redundant looping when we only want to know if a list is smaller then some size.
also remove paranoid NULL check in list counting.
Diffstat (limited to 'source/blender/blenlib/intern/listbase.c')
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index cd2e343560f..ea33b9b1e3b 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -372,6 +372,17 @@ void BLI_freelistN(ListBase *listbase) BLI_listbase_clear(listbase); } +int BLI_listbase_count_ex(const ListBase *listbase, const int count_max) +{ + Link *link; + int count = 0; + + for (link = listbase->first; link && count != count_max; link = link->next) { + count++; + } + + return count; +} /** * Returns the number of elements in \a listbase. @@ -380,14 +391,11 @@ int BLI_listbase_count(const ListBase *listbase) { Link *link; int count = 0; - - if (listbase) { - link = listbase->first; - while (link) { - count++; - link = link->next; - } + + for (link = listbase->first; link; link = link->next) { + count++; } + return count; } |