Ticket #326: avoid_string_appends_1.patch
File avoid_string_appends_1.patch, 3.8 KB (added by , 16 years ago) |
---|
-
chert_postlist.h
86 86 /// Compose a key from a termname and docid. 87 87 static string make_key(const string & term, Xapian::docid did) { 88 88 string key = make_key(term); 89 key += pack_uint_preserving_sort(did);89 append_packed_uint_preserving_sort(key, did); 90 90 return key; 91 91 } 92 92 -
chert_positionlist.cc
70 70 did << ", " << term); 71 71 72 72 string data; 73 if (!get_exact_entry(pack_uint_preserving_sort(did) + term, data)) { 73 string key; 74 // 5 bytes is usually enough for a packed uint 75 key.reserve(5 + term.size()); 76 append_packed_uint_preserving_sort(key, did); 77 key.append(term); 78 if (!get_exact_entry(key, data)) { 74 79 // There's no positional information for this term. 75 80 return 0; 76 81 } … … 106 111 positions.clear(); 107 112 108 113 string data; 109 if (!table->get_exact_entry(pack_uint_preserving_sort(did) + tname, data)) { 114 string key; 115 // 5 bytes is usually enough for a packed uint 116 key.reserve(5 + tname.size()); 117 append_packed_uint_preserving_sort(key, did); 118 key.append(tname); 119 if (!table->get_exact_entry(key, data)) { 110 120 // There's no positional information for this term. 111 121 current_pos = positions.begin(); 112 122 return false; -
chert_utils.h
224 224 * of 256 bytes on the length of the integer. However, this is unlikely to 225 225 * ever be a problem. 226 226 * 227 * @param result A string to append the representation of the integer to. 227 228 * @param value The integer to represent. 228 *229 * @result A string containing the representation of the integer.230 229 */ 231 230 template<class T> 232 string 233 pack_uint_preserving_sort(T value)231 void 232 append_packed_uint_preserving_sort(string & result, T value) 234 233 { 235 234 // Check unsigned 236 235 STATIC_ASSERT_UNSIGNED_TYPE(T); 237 236 238 string result;237 string::size_type start = result.size(); 239 238 while (value != 0) { 240 239 om_byte part = static_cast<om_byte>(value & 0xff); 241 240 value = value >> 8; 242 result.insert(st ring::size_type(0), 1u, char(part));241 result.insert(start, 1u, char(part)); 243 242 } 244 result.insert(string::size_type(0), 1u, char(result.size())); 245 return result; 243 result.insert(start, 1u, char(result.size() - start)); 246 244 } 247 245 248 246 /** Unpack a unsigned integer, store in sort preserving order. … … 401 399 inline string 402 400 chert_docid_to_key(Xapian::docid did) 403 401 { 404 return pack_uint_preserving_sort(did); 402 string result; 403 append_packed_uint_preserving_sort(result, did); 404 return result; 405 405 } 406 406 407 407 #endif /* OM_HGUARD_CHERT_UTILS_H */ -
chert_positionlist.h
34 34 35 35 class ChertPositionListTable : public ChertTable { 36 36 static string make_key(Xapian::docid did, const string & tname) { 37 return pack_uint_preserving_sort(did) + tname; 37 string result; 38 // 5 bytes is usually enough for a packed uint 39 result.reserve(5 + tname.size()); 40 append_packed_uint_preserving_sort(result, did); 41 result.append(tname); 42 return result + tname; 38 43 } 39 44 40 45 public: -
chert_values.h
37 37 { 38 38 std::string key("\0\xd8", 2); 39 39 key += pack_uint(slot); 40 key += pack_uint_preserving_sort(did);40 append_packed_uint_preserving_sort(key, did); 41 41 return key; 42 42 } 43 43