From: Leon W. <moo...@us...> - 2005-04-14 11:38:05
|
Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11612 Modified Files: SyntaxFile.cpp SyntaxFile.h Log Message: Improved Class - Removed keyword array's to save memory - Rewrote Delimited keyword functions, to read them from the xml tree. - Constructor used less iterations to read space delimited cached sets, so it should improve speed. Index: SyntaxFile.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/SyntaxFile.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** SyntaxFile.cpp 11 Apr 2005 08:20:27 -0000 1.27 --- SyntaxFile.cpp 14 Apr 2005 11:37:46 -0000 1.28 *************** *** 51,63 **** CSyntaxFile::CSyntaxFile() { - int iCount; - iMaxStyle = STYLE_MAX; - - // Set the string compare functions for the CSortedArray's with keywords. - for( iCount = 0; iCount < KEYWORDSET_MAX; ++ iCount ) - { - Keywords[iCount].SetCompareFunction( CompareCString ); - } } --- 51,55 ---- *************** *** 70,75 **** { int iCount; - unsigned int iWordCount; - char number[4]; pug::xml_node xnode; --- 62,65 ---- *************** *** 99,131 **** for( iCount = 0; iCount < KEYWORDSET_MAX; ++ iCount ) { ! sprintf( number, "%i", iCount ); ! ! xnode = m_xml_parser.document().first_element_by_attribute( TAG_KEYWORDS, ATT_KEYWORDS_SET, number );//(LPCTSTR)CString().Format( "%i", iCount ) ); ! if( xnode.empty() ) continue; ! ! CString szKeywordDescription; ! if( !xnode.attribute( ATT_KEYWORDS_DESCRIPTION ).empty() ) ! { ! szKeywordDescription = xnode.attribute( ATT_KEYWORDS_DESCRIPTION ).value(); ! if( szKeywordDescription.IsEmpty() ) ! { ! szKeywordDescription = "Keywords "; ! char descnumber[4]; ! sprintf( descnumber, "%d", iCount + 1 ); ! szKeywordDescription += descnumber; ! } ! } ! ! KeywordDescription[iCount] = szKeywordDescription; ! ! for( iWordCount = 0; iWordCount < xnode.children(); ++ iWordCount ) ! { ! if( CString( xnode.child( iWordCount ).name() ) == TAG_KEYWORDS_WORD && xnode.child( iWordCount ).children() ) ! { ! Keywords[iCount].Add( CString( xnode.child( iWordCount ).child(0).value() ) ); ! if( iWordCount > 0 ) KeywordsSpaceDelimited[iCount] += _T(" "); ! KeywordsSpaceDelimited[iCount] += CString( xnode.child( iWordCount ).child(0).value() ); ! } ! } } --- 89,93 ---- for( iCount = 0; iCount < KEYWORDSET_MAX; ++ iCount ) { ! KeywordsSpaceDelimited[iCount] = GetDelimitedKeywordSet( iCount, ' ' ); } *************** *** 135,149 **** CString CSyntaxFile::GetKeywordSetDescription(int iSet) { if( iSet < 0 || iSet >= KEYWORDSET_MAX ) return _T(""); // Make sure the file is parsed. if( !m_bParsed && !Parse() ) return _T(""); ! ! return KeywordDescription[iSet]; } bool CSyntaxFile::SetDelimitedKeywordSet( int iSet, CString &szKeywords, char cSep /* = ' ' */) { - int iCount; char number[4]; CString szKeyword; --- 97,116 ---- CString CSyntaxFile::GetKeywordSetDescription(int iSet) { + char number[4]; + if( iSet < 0 || iSet >= KEYWORDSET_MAX ) return _T(""); // Make sure the file is parsed. if( !m_bParsed && !Parse() ) return _T(""); ! ! sprintf( number, "%i", iSet ); ! pug::xml_node xnode = m_xml_parser.document().first_element_by_attribute( TAG_KEYWORDS, ATT_KEYWORDS_SET, number ); ! if( xnode.empty() ) return _T(""); ! ! return GetStringAttributeFromXMLFile( xnode, ATT_KEYWORDS_DESCRIPTION ); } bool CSyntaxFile::SetDelimitedKeywordSet( int iSet, CString &szKeywords, char cSep /* = ' ' */) { char number[4]; CString szKeyword; *************** *** 154,160 **** if( !m_bParsed && !Parse() ) return false; KeywordsSpaceDelimited[iSet].Empty(); - Keywords[iSet].RemoveAll(); int iBegin = 0; int iEnd = 0; --- 121,131 ---- if( !m_bParsed && !Parse() ) return false; + sprintf( number, "%i", iSet ); + pug::xml_node xnode( m_xml_parser.document().first_element_by_attribute( TAG_KEYWORDS, ATT_KEYWORDS_SET, number ) ); + if( xnode.empty() ) return false; + + while( xnode.has_child_nodes() ) xnode.remove_child(0); KeywordsSpaceDelimited[iSet].Empty(); int iBegin = 0; int iEnd = 0; *************** *** 176,180 **** if( !szKeyword.IsEmpty() ) { ! Keywords[iSet].Add( szKeyword ); if( iBegin > 0 ) KeywordsSpaceDelimited[iSet] += _T(" "); KeywordsSpaceDelimited[iSet] += szKeyword; --- 147,151 ---- if( !szKeyword.IsEmpty() ) { ! AddChildStringElement( xnode, TAG_KEYWORDS_WORD, szKeyword ); if( iBegin > 0 ) KeywordsSpaceDelimited[iSet] += _T(" "); KeywordsSpaceDelimited[iSet] += szKeyword; *************** *** 183,204 **** } - sprintf( number, "%i", iSet ); - - pug::xml_node xnode( m_xml_parser.document().first_element_by_attribute( TAG_KEYWORDS, ATT_KEYWORDS_SET, number ) ); - if( xnode.empty() ) return false; - - while( xnode.has_child_nodes() ) xnode.remove_child(0); - - if( Keywords[iSet].GetSize() > 0 ) - { - for( iCount = 0; iCount < Keywords[iSet].GetSize(); ++ iCount ) - { - xnode.insert_child( iCount, pug::node_element ); - xnode.child( iCount ).name( "Word" ); - xnode.child( iCount ).insert_child( 0, pug::node_pcdata ); - ( xnode.child( iCount ) ).child(0).value( Keywords[iSet][iCount] ); - } - } - return m_bModified = true; } --- 154,157 ---- *************** *** 218,223 **** CString CSyntaxFile::GetDelimitedKeywordSet( int iSet, char cSep ) { ! int iCount; CString szDelimited; if( iSet < 0 || iSet >= KEYWORDSET_MAX ) return _T(""); --- 171,178 ---- CString CSyntaxFile::GetDelimitedKeywordSet( int iSet, char cSep ) { ! char number[4]; ! int iWordCount; CString szDelimited; + pug::xml_node xnode; if( iSet < 0 || iSet >= KEYWORDSET_MAX ) return _T(""); *************** *** 226,243 **** if( !m_bParsed && !Parse() ) return _T(""); ! if( 0 == Keywords[iSet].GetSize() ) return _T(""); ! for( iCount = 0; iCount < Keywords[iSet].GetSize(); ++ iCount ) { ! if( 0 != iCount ) ! { ! szDelimited += cSep; ! szDelimited += Keywords[iSet][iCount]; ! } ! else { ! szDelimited = Keywords[iSet][iCount]; } } return szDelimited; } --- 181,197 ---- if( !m_bParsed && !Parse() ) return _T(""); ! sprintf( number, "%i", iSet ); ! xnode = m_xml_parser.document().first_element_by_attribute( TAG_KEYWORDS, ATT_KEYWORDS_SET, number ); ! if( xnode.empty() ) return _T(""); ! for( iWordCount = 0; iWordCount < xnode.children(); ++ iWordCount ) { ! if( CString( xnode.child( iWordCount ).name() ) == TAG_KEYWORDS_WORD && xnode.child( iWordCount ).children() ) { ! if( iWordCount > 0 ) szDelimited += cSep; ! szDelimited += CString( xnode.child( iWordCount ).child(0).value() ); } } + return szDelimited; } *************** *** 246,251 **** --- 200,208 ---- CString CSyntaxFile::GetDelimitedKeywords( char cSep ) { + char number[4]; int iCount; + int iWordCount; CString szDelimited; + pug::xml_node xnode; CSortedArray<CString, CString> AllKeywords; *************** *** 257,265 **** for( iCount = 0; iCount < KEYWORDSET_MAX; ++ iCount ) { ! if( Keywords[iCount].GetSize() ) { ! AllKeywords.Append( Keywords[iCount] ); } } AllKeywords.Sort(); for( iCount = 0; iCount < AllKeywords.GetSize(); ++ iCount ) --- 214,230 ---- for( iCount = 0; iCount < KEYWORDSET_MAX; ++ iCount ) { ! sprintf( number, "%i", iCount ); ! xnode = m_xml_parser.document().first_element_by_attribute( TAG_KEYWORDS, ATT_KEYWORDS_SET, number ); ! if( xnode.empty() ) continue; ! ! for( iWordCount = 0; iWordCount < xnode.children(); ++ iWordCount ) { ! if( CString( xnode.child( iWordCount ).name() ) == TAG_KEYWORDS_WORD && xnode.child( iWordCount ).children() ) ! { ! AllKeywords.Add( CString( xnode.child( iWordCount ).child(0).value() ) ); ! } } } + AllKeywords.Sort(); for( iCount = 0; iCount < AllKeywords.GetSize(); ++ iCount ) Index: SyntaxFile.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/SyntaxFile.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** SyntaxFile.h 11 Apr 2005 06:52:58 -0000 1.18 --- SyntaxFile.h 14 Apr 2005 11:37:55 -0000 1.19 *************** *** 151,160 **** int iMaxStyle; - /// Sorted array with all the keywords of a language - CSortedArray<CString, CString> Keywords[KEYWORDSET_MAX]; - - /// Array with the descriptions of the Keyword Sets - CString KeywordDescription[KEYWORDSET_MAX]; - /// Array with strings containing the all keywords of a set delimited by a space. CString KeywordsSpaceDelimited[KEYWORDSET_MAX]; --- 151,154 ---- |