From: Julian Seward Date: Thu, 13 Nov 2008 13:17:06 +0000 (+0000) Subject: Add performance comments to VG_(sizeFM), and add new method X-Git-Tag: svn/VALGRIND_3_4_0~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24917a1daa9f8a4a5d222a3948c3860bc051455a;p=thirdparty%2Fvalgrind.git Add performance comments to VG_(sizeFM), and add new method VG_(isEmptyFM), currently commented out. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8765 --- diff --git a/coregrind/m_wordfm.c b/coregrind/m_wordfm.c index 2ddc795dc9..90389cd4d9 100644 --- a/coregrind/m_wordfm.c +++ b/coregrind/m_wordfm.c @@ -683,12 +683,19 @@ Bool VG_(findBoundsFM)( WordFM* fm, key, fm->kCmp ); } +// See comment in pub_tool_wordfm.h for performance warning UWord VG_(sizeFM) ( WordFM* fm ) { // Hmm, this is a bad way to do this return fm->root ? size_avl_nonNull( fm->root ) : 0; } +// NB UNTESTED! TEST BEFORE USE! +//Bool VG_(isEmptyFM)( WordFM* fm ) +//{ +// return fm->root ? False : True; +//} + // set up FM for iteration void VG_(initIterFM) ( WordFM* fm ) { diff --git a/include/pub_tool_wordfm.h b/include/pub_tool_wordfm.h index 7b9949024d..6302a9a25b 100644 --- a/include/pub_tool_wordfm.h +++ b/include/pub_tool_wordfm.h @@ -122,9 +122,16 @@ Bool VG_(findBoundsFM)( WordFM* fm, UWord maxKey, UWord maxVal, UWord key ); -// How many elements are there in fm? +// How many elements are there in fm? NOTE: dangerous in the +// sense that this is not an O(1) operation but rather O(N), +// since it involves walking the whole tree. UWord VG_(sizeFM) ( WordFM* fm ); +// Is fm empty? This at least is an O(1) operation. +// Code is present in m_wordfm.c but commented out due to no +// current usage. Un-comment (and TEST IT) if required. +//Bool VG_(isEmptyFM)( WordFM* fm ); + // set up FM for iteration void VG_(initIterFM) ( WordFM* fm );