From c910aa5a42fb789225bb58c990d077d39da9b4ce Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Wed, 31 Aug 2016 17:21:53 -0400 Subject: Cache lines on API side to avoid UI hangs with large basic blocks --- functiongraphblock.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'functiongraphblock.cpp') diff --git a/functiongraphblock.cpp b/functiongraphblock.cpp index af330497..436339f6 100644 --- a/functiongraphblock.cpp +++ b/functiongraphblock.cpp @@ -27,6 +27,8 @@ using namespace std; FunctionGraphBlock::FunctionGraphBlock(BNFunctionGraphBlock* block) { m_object = block; + m_cachedLinesValid = false; + m_cachedEdgesValid = false; } @@ -72,8 +74,11 @@ int FunctionGraphBlock::GetHeight() const } -vector FunctionGraphBlock::GetLines() const +const vector& FunctionGraphBlock::GetLines() { + if (m_cachedLinesValid) + return m_cachedLines; + size_t count; BNDisassemblyTextLine* lines = BNGetFunctionGraphBlockLines(m_object, &count); @@ -96,12 +101,17 @@ vector FunctionGraphBlock::GetLines() const } BNFreeDisassemblyTextLines(lines, count); - return result; + m_cachedLines = result; + m_cachedLinesValid = true; + return m_cachedLines; } -vector FunctionGraphBlock::GetOutgoingEdges() const +const vector& FunctionGraphBlock::GetOutgoingEdges() { + if (m_cachedEdgesValid) + return m_cachedEdges; + size_t count; BNFunctionGraphEdge* edges = BNGetFunctionGraphBlockOutgoingEdges(m_object, &count); @@ -117,5 +127,7 @@ vector FunctionGraphBlock::GetOutgoingEdges() const } BNFreeFunctionGraphBlockOutgoingEdgeList(edges, count); - return result; + m_cachedEdges = result; + m_cachedEdgesValid = true; + return m_cachedEdges; } -- cgit v1.3.1