author | zautrix <zautrix> | 2004-10-22 02:21:29 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-22 02:21:29 (UTC) |
commit | c17118a0b2da49ec633e21cdcd51798c0c38644a (patch) (unidiff) | |
tree | 581fbcaa64a5566991ffe0bd3b1b2d428589d87f /kabc/vcard | |
parent | d6f9bd535e8cabe653bdff329500f9153e5e11fb (diff) | |
download | kdepimpi-c17118a0b2da49ec633e21cdcd51798c0c38644a.zip kdepimpi-c17118a0b2da49ec633e21cdcd51798c0c38644a.tar.gz kdepimpi-c17118a0b2da49ec633e21cdcd51798c0c38644a.tar.bz2 |
made addressbook much faster
-rw-r--r-- | kabc/vcard/VCardEntity.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/kabc/vcard/VCardEntity.cpp b/kabc/vcard/VCardEntity.cpp index 5fca3bc..b676cc7 100644 --- a/kabc/vcard/VCardEntity.cpp +++ b/kabc/vcard/VCardEntity.cpp | |||
@@ -44,86 +44,131 @@ VCardEntity::VCardEntity(const QCString & s) | |||
44 | :Entity(s) | 44 | :Entity(s) |
45 | { | 45 | { |
46 | cardList_.setAutoDelete( TRUE ); | 46 | cardList_.setAutoDelete( TRUE ); |
47 | } | 47 | } |
48 | 48 | ||
49 | VCardEntity & | 49 | VCardEntity & |
50 | VCardEntity::operator = (VCardEntity & x) | 50 | VCardEntity::operator = (VCardEntity & x) |
51 | { | 51 | { |
52 | if (*this == x) return *this; | 52 | if (*this == x) return *this; |
53 | 53 | ||
54 | Entity::operator = (x); | 54 | Entity::operator = (x); |
55 | return *this; | 55 | return *this; |
56 | } | 56 | } |
57 | 57 | ||
58 | VCardEntity & | 58 | VCardEntity & |
59 | VCardEntity::operator = (const QCString & s) | 59 | VCardEntity::operator = (const QCString & s) |
60 | { | 60 | { |
61 | Entity::operator = (s); | 61 | Entity::operator = (s); |
62 | return *this; | 62 | return *this; |
63 | } | 63 | } |
64 | 64 | ||
65 | bool | 65 | bool |
66 | VCardEntity::operator == (VCardEntity & x) | 66 | VCardEntity::operator == (VCardEntity & x) |
67 | { | 67 | { |
68 | x.parse(); | 68 | x.parse(); |
69 | return false; | 69 | return false; |
70 | } | 70 | } |
71 | 71 | ||
72 | VCardEntity::~VCardEntity() | 72 | VCardEntity::~VCardEntity() |
73 | { | 73 | { |
74 | } | 74 | } |
75 | 75 | ||
76 | #include <qdatetime.h>; | ||
76 | void | 77 | void |
77 | VCardEntity::_parse() | 78 | VCardEntity::_parse() |
78 | { | 79 | { |
80 | #if 0 | ||
81 | QTime tim; | ||
82 | tim.start(); | ||
83 | int num = 0; | ||
84 | // old code | ||
79 | vDebug("parse"); | 85 | vDebug("parse"); |
80 | QCString s(strRep_); | 86 | QCString s(strRep_); |
81 | 87 | ||
82 | int i = s.find(QRegExp("BEGIN:VCARD", false)); | 88 | int i = s.find(QRegExp("BEGIN:VCARD", false)); |
83 | 89 | ||
84 | while (i != -1) { | 90 | while (i != -1) { |
85 | 91 | ||
86 | i = s.find(QRegExp("BEGIN:VCARD", false), 11); | 92 | i = s.find(QRegExp("BEGIN:VCARD", false), 11); |
87 | 93 | ||
88 | QCString cardStr(s.left(i)); | 94 | QCString cardStr(s.left(i)); |
89 | 95 | ||
90 | VCard * v = new VCard(cardStr); | 96 | VCard * v = new VCard(cardStr); |
91 | 97 | ||
92 | cardList_.append(v); | 98 | cardList_.append(v); |
93 | 99 | ||
94 | v->parse(); | 100 | v->parse(); |
95 | 101 | ||
96 | s.remove(0, i); | 102 | s.remove(0, i); |
97 | } | 103 | } |
104 | |||
105 | #else | ||
106 | // this code is up to 17 (!) times faster | ||
107 | int start = 0; | ||
108 | QTime tim; | ||
109 | tim.start(); | ||
110 | int i = 11; | ||
111 | int len = strRep_.length(); | ||
112 | int num = 0; | ||
113 | while (i < len ) { | ||
114 | while( i < len ) { | ||
115 | int add = 1; | ||
116 | if ( strRep_.at(i) == 'B' ) { | ||
117 | if ( i+add < len && strRep_.at(i+add++) == 'E') | ||
118 | if ( i+add < len && strRep_.at(i+add++) == 'G') | ||
119 | if ( i+add < len && strRep_.at(i+add++) == 'I') | ||
120 | if ( i+add < len && strRep_.at(i+add++) == 'N') | ||
121 | if ( i+add < len && strRep_.at(i+add++) == ':') | ||
122 | if ( i+add < len && strRep_.at(i+add++) == 'V') | ||
123 | if ( i+add < len && strRep_.at(i+add++) == 'C') | ||
124 | if ( i+add < len && strRep_.at(i+add++) == 'A') | ||
125 | if ( i+add < len && strRep_.at(i+add++) == 'R') | ||
126 | if ( i+add < len && strRep_.at(i+add++) == 'D') | ||
127 | break; | ||
128 | } | ||
129 | ++i; | ||
130 | } | ||
131 | if ( i <= len ) { | ||
132 | ++num; | ||
133 | char* dat = strRep_.data()+start; | ||
134 | VCard * v = new VCard( QCString ( dat,i-start ) ); | ||
135 | start = i; | ||
136 | cardList_.append(v); | ||
137 | v->parse(); | ||
138 | } | ||
139 | i+= 11; | ||
140 | } | ||
141 | #endif | ||
142 | //qDebug("***time %d found %d", tim.elapsed(), num); | ||
98 | } | 143 | } |
99 | 144 | ||
100 | void | 145 | void |
101 | VCardEntity::_assemble() | 146 | VCardEntity::_assemble() |
102 | { | 147 | { |
103 | VCardListIterator it(cardList_); | 148 | VCardListIterator it(cardList_); |
104 | 149 | ||
105 | for (; it.current(); ++it) | 150 | for (; it.current(); ++it) |
106 | strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. | 151 | strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. |
107 | } | 152 | } |
108 | 153 | ||
109 | VCardList & | 154 | VCardList & |
110 | VCardEntity::cardList() | 155 | VCardEntity::cardList() |
111 | { | 156 | { |
112 | parse(); | 157 | parse(); |
113 | return cardList_; | 158 | return cardList_; |
114 | } | 159 | } |
115 | 160 | ||
116 | void | 161 | void |
117 | VCardEntity::setCardList(const VCardList & l) | 162 | VCardEntity::setCardList(const VCardList & l) |
118 | { | 163 | { |
119 | parse(); | 164 | parse(); |
120 | //UScardList_ = l; | 165 | //UScardList_ = l; |
121 | VCardListIterator it(l); | 166 | VCardListIterator it(l); |
122 | 167 | ||
123 | for (; it.current(); ++it) { | 168 | for (; it.current(); ++it) { |
124 | VCard* v = new VCard(*it.current()); | 169 | VCard* v = new VCard(*it.current()); |
125 | cardList_.append(v); | 170 | cardList_.append(v); |
126 | } | 171 | } |
127 | 172 | ||
128 | } | 173 | } |
129 | 174 | ||