Skip to content

Commit

Permalink
Minor optimization in TBSpaceAllocator
Browse files Browse the repository at this point in the history
  • Loading branch information
fruxo committed May 3, 2014
1 parent a0a41e2 commit d7f56ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/tb/tb_bitmap_fragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ int TBGetNearestPowerOfTwo(int val)

// == TBSpaceAllocator ======================================================================================

bool TBSpaceAllocator::HasSpace(int needed_w) const
{
if (needed_w > m_available_space)
return false;
if (IsAllAvailable())
return true;
for (Space *fs = m_free_space_list.GetFirst(); fs; fs = fs->GetNext())
{
if (needed_w <= fs->width)
return true;
}
return false;
}

TBSpaceAllocator::Space *TBSpaceAllocator::AllocSpace(int needed_w)
{
if (Space *available_space = GetSmallestAvailableSpace(needed_w))
Expand Down
2 changes: 1 addition & 1 deletion src/tb/tb_bitmap_fragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TBSpaceAllocator
bool IsAllAvailable() const { return !m_used_space_list.HasLinks(); }

/** Return true if the given width is currently available. */
bool HasSpace(int needed_w) { return !!GetSmallestAvailableSpace(needed_w); }
bool HasSpace(int needed_w) const;

/** Allocate the given space and return the Space, or nullptr on error. */
Space *AllocSpace(int needed_w);
Expand Down

0 comments on commit d7f56ab

Please sign in to comment.