author | simon <simon> | 2002-03-20 21:08:03 (UTC) |
---|---|---|
committer | simon <simon> | 2002-03-20 21:08:03 (UTC) |
commit | 60b86269c6087dfb6674de6dc01d71a9a6d6d180 (patch) (unidiff) | |
tree | e53c76de63500dfe52b90c3da6c354b507cb4ba0 | |
parent | 79d96ab3393af185b0f0d705e1b7ae74ee801241 (diff) | |
download | opie-60b86269c6087dfb6674de6dc01d71a9a6d6d180.zip opie-60b86269c6087dfb6674de6dc01d71a9a6d6d180.tar.gz opie-60b86269c6087dfb6674de6dc01d71a9a6d6d180.tar.bz2 |
- speed up for attribute() and setAttribute()
- indentation fixlet (let's stay consistent :)
-rw-r--r-- | libopie/xmltree.cc | 17 | ||||
-rw-r--r-- | libopie2/opiecore/xmltree.cc | 17 |
2 files changed, 20 insertions, 14 deletions
diff --git a/libopie/xmltree.cc b/libopie/xmltree.cc index 3d03cc6..408e3c6 100644 --- a/libopie/xmltree.cc +++ b/libopie/xmltree.cc | |||
@@ -76,44 +76,46 @@ void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild ) | |||
76 | 76 | ||
77 | if ( newChild->m_parent && newChild != refChild ) | 77 | if ( newChild->m_parent && newChild != refChild ) |
78 | newChild->m_parent->removeChild( newChild ); | 78 | newChild->m_parent->removeChild( newChild ); |
79 | 79 | ||
80 | newChild->m_parent = this; | 80 | newChild->m_parent = this; |
81 | 81 | ||
82 | XMLElement *next = refChild->m_next; | 82 | XMLElement *next = refChild->m_next; |
83 | 83 | ||
84 | refChild->m_next = newChild; | 84 | refChild->m_next = newChild; |
85 | 85 | ||
86 | newChild->m_prev = refChild; | 86 | newChild->m_prev = refChild; |
87 | newChild->m_next = next; | 87 | newChild->m_next = next; |
88 | 88 | ||
89 | if ( next ) | 89 | if ( next ) |
90 | next->m_prev = newChild; | 90 | next->m_prev = newChild; |
91 | } | 91 | } |
92 | QString XMLElement::attribute(const QString &attr )const | 92 | |
93 | QString XMLElement::attribute( const QString &attr ) const | ||
93 | { | 94 | { |
94 | if ( !m_attributes.contains( attr ) ) | ||
95 | return QString::null; | ||
96 | AttributeMap::ConstIterator it = m_attributes.find( attr ); | 95 | AttributeMap::ConstIterator it = m_attributes.find( attr ); |
96 | if ( it == m_attributes.end() ) | ||
97 | return QString::null; | ||
97 | return it.data(); | 98 | return it.data(); |
98 | } | 99 | } |
99 | void XMLElement::setAttribute(const QString &attr, const QString &value ) | 100 | |
101 | void XMLElement::setAttribute( const QString &attr, const QString &value ) | ||
100 | { | 102 | { |
101 | m_attributes.remove( attr ); | 103 | m_attributes.replace( attr, value ); |
102 | m_attributes.insert( attr, value ); | ||
103 | } | 104 | } |
105 | |||
104 | void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild ) | 106 | void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild ) |
105 | { | 107 | { |
106 | assert( refChild ); | 108 | assert( refChild ); |
107 | assert( refChild->m_parent ); | 109 | assert( refChild->m_parent ); |
108 | assert( refChild->m_parent == this ); | 110 | assert( refChild->m_parent == this ); |
109 | assert( newChild != refChild ); | 111 | assert( newChild != refChild ); |
110 | 112 | ||
111 | if ( newChild->m_parent && newChild != refChild ) | 113 | if ( newChild->m_parent && newChild != refChild ) |
112 | newChild->m_parent->removeChild( newChild ); | 114 | newChild->m_parent->removeChild( newChild ); |
113 | 115 | ||
114 | newChild->m_parent = this; | 116 | newChild->m_parent = this; |
115 | 117 | ||
116 | XMLElement *prev = refChild->m_prev; | 118 | XMLElement *prev = refChild->m_prev; |
117 | 119 | ||
118 | refChild->m_prev = newChild; | 120 | refChild->m_prev = newChild; |
119 | 121 | ||
@@ -302,17 +304,18 @@ XMLElement *XMLElement::load( const QString &fileName ) | |||
302 | if ( !f.open( IO_ReadOnly ) ) | 304 | if ( !f.open( IO_ReadOnly ) ) |
303 | return 0; | 305 | return 0; |
304 | 306 | ||
305 | QTextStream stream( &f ); | 307 | QTextStream stream( &f ); |
306 | stream.setEncoding( QTextStream::UnicodeUTF8 ); | 308 | stream.setEncoding( QTextStream::UnicodeUTF8 ); |
307 | QXmlInputSource src( stream ); | 309 | QXmlInputSource src( stream ); |
308 | QXmlSimpleReader reader; | 310 | QXmlSimpleReader reader; |
309 | Handler handler; | 311 | Handler handler; |
310 | 312 | ||
311 | reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); | 313 | reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); |
312 | reader.setContentHandler( &handler ); | 314 | reader.setContentHandler( &handler ); |
313 | reader.parse( src ); | 315 | reader.parse( src ); |
314 | 316 | ||
315 | return handler.root();; | 317 | return handler.root();; |
316 | } | 318 | } |
317 | 319 | ||
318 | 320 | /* vim: et sw=4 | |
321 | */ | ||
diff --git a/libopie2/opiecore/xmltree.cc b/libopie2/opiecore/xmltree.cc index 3d03cc6..408e3c6 100644 --- a/libopie2/opiecore/xmltree.cc +++ b/libopie2/opiecore/xmltree.cc | |||
@@ -76,44 +76,46 @@ void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild ) | |||
76 | 76 | ||
77 | if ( newChild->m_parent && newChild != refChild ) | 77 | if ( newChild->m_parent && newChild != refChild ) |
78 | newChild->m_parent->removeChild( newChild ); | 78 | newChild->m_parent->removeChild( newChild ); |
79 | 79 | ||
80 | newChild->m_parent = this; | 80 | newChild->m_parent = this; |
81 | 81 | ||
82 | XMLElement *next = refChild->m_next; | 82 | XMLElement *next = refChild->m_next; |
83 | 83 | ||
84 | refChild->m_next = newChild; | 84 | refChild->m_next = newChild; |
85 | 85 | ||
86 | newChild->m_prev = refChild; | 86 | newChild->m_prev = refChild; |
87 | newChild->m_next = next; | 87 | newChild->m_next = next; |
88 | 88 | ||
89 | if ( next ) | 89 | if ( next ) |
90 | next->m_prev = newChild; | 90 | next->m_prev = newChild; |
91 | } | 91 | } |
92 | QString XMLElement::attribute(const QString &attr )const | 92 | |
93 | QString XMLElement::attribute( const QString &attr ) const | ||
93 | { | 94 | { |
94 | if ( !m_attributes.contains( attr ) ) | ||
95 | return QString::null; | ||
96 | AttributeMap::ConstIterator it = m_attributes.find( attr ); | 95 | AttributeMap::ConstIterator it = m_attributes.find( attr ); |
96 | if ( it == m_attributes.end() ) | ||
97 | return QString::null; | ||
97 | return it.data(); | 98 | return it.data(); |
98 | } | 99 | } |
99 | void XMLElement::setAttribute(const QString &attr, const QString &value ) | 100 | |
101 | void XMLElement::setAttribute( const QString &attr, const QString &value ) | ||
100 | { | 102 | { |
101 | m_attributes.remove( attr ); | 103 | m_attributes.replace( attr, value ); |
102 | m_attributes.insert( attr, value ); | ||
103 | } | 104 | } |
105 | |||
104 | void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild ) | 106 | void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild ) |
105 | { | 107 | { |
106 | assert( refChild ); | 108 | assert( refChild ); |
107 | assert( refChild->m_parent ); | 109 | assert( refChild->m_parent ); |
108 | assert( refChild->m_parent == this ); | 110 | assert( refChild->m_parent == this ); |
109 | assert( newChild != refChild ); | 111 | assert( newChild != refChild ); |
110 | 112 | ||
111 | if ( newChild->m_parent && newChild != refChild ) | 113 | if ( newChild->m_parent && newChild != refChild ) |
112 | newChild->m_parent->removeChild( newChild ); | 114 | newChild->m_parent->removeChild( newChild ); |
113 | 115 | ||
114 | newChild->m_parent = this; | 116 | newChild->m_parent = this; |
115 | 117 | ||
116 | XMLElement *prev = refChild->m_prev; | 118 | XMLElement *prev = refChild->m_prev; |
117 | 119 | ||
118 | refChild->m_prev = newChild; | 120 | refChild->m_prev = newChild; |
119 | 121 | ||
@@ -302,17 +304,18 @@ XMLElement *XMLElement::load( const QString &fileName ) | |||
302 | if ( !f.open( IO_ReadOnly ) ) | 304 | if ( !f.open( IO_ReadOnly ) ) |
303 | return 0; | 305 | return 0; |
304 | 306 | ||
305 | QTextStream stream( &f ); | 307 | QTextStream stream( &f ); |
306 | stream.setEncoding( QTextStream::UnicodeUTF8 ); | 308 | stream.setEncoding( QTextStream::UnicodeUTF8 ); |
307 | QXmlInputSource src( stream ); | 309 | QXmlInputSource src( stream ); |
308 | QXmlSimpleReader reader; | 310 | QXmlSimpleReader reader; |
309 | Handler handler; | 311 | Handler handler; |
310 | 312 | ||
311 | reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); | 313 | reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); |
312 | reader.setContentHandler( &handler ); | 314 | reader.setContentHandler( &handler ); |
313 | reader.parse( src ); | 315 | reader.parse( src ); |
314 | 316 | ||
315 | return handler.root();; | 317 | return handler.root();; |
316 | } | 318 | } |
317 | 319 | ||
318 | 320 | /* vim: et sw=4 | |
321 | */ | ||