comparison src/org/tmatesoft/hg/repo/HgChangelog.java @ 656:a937e63b6e02

Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 04 Jul 2013 18:40:03 +0200
parents 6526d8adbc0f
children fba85bc1dfb8
comparison
equal deleted inserted replaced
655:bcbcc318f250 656:a937e63b6e02
303 long unixTime = Long.parseLong(_timeString.substring(0, space1)); 303 long unixTime = Long.parseLong(_timeString.substring(0, space1));
304 int _timezone = Integer.parseInt(_timeString.substring(space1 + 1, space2)); 304 int _timezone = Integer.parseInt(_timeString.substring(space1 + 1, space2));
305 // unixTime is local time, and timezone records difference of the local time to UTC. 305 // unixTime is local time, and timezone records difference of the local time to UTC.
306 Date _time = new Date(unixTime * 1000); 306 Date _time = new Date(unixTime * 1000);
307 String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null; 307 String _extras = space2 < _timeString.length() ? _timeString.substring(space2 + 1) : null;
308 Map<String, String> _extrasMap; 308 Map<String, String> _extrasMap = parseExtras(_extras);
309 final String extras_branch_key = "branch";
310 if (_extras == null || _extras.trim().length() == 0) {
311 _extrasMap = Collections.singletonMap(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME);
312 } else {
313 _extrasMap = new HashMap<String, String>();
314 for (String pair : _extras.split("\00")) {
315 pair = decode(pair);
316 int eq = pair.indexOf(':');
317 _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1));
318 }
319 if (!_extrasMap.containsKey(extras_branch_key)) {
320 _extrasMap.put(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME);
321 }
322 _extrasMap = Collections.unmodifiableMap(_extrasMap);
323 }
324
325 // 309 //
326 int lastStart = breakIndex3 + 1; 310 int lastStart = breakIndex3 + 1;
327 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex); 311 int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
328 ArrayList<String> _files = null; 312 ArrayList<String> _files = null;
329 if (breakIndex4 > lastStart) { 313 if (breakIndex4 > lastStart) {
330 // if breakIndex4 == lastStart, we already found \n\n and hence there are no files (e.g. merge revision) 314 // if breakIndex4 == lastStart, we already found \n\n and hence there are no files (e.g. merge revision)
331 _files = new ArrayList<String>(5); 315 _files = new ArrayList<String>(5);
316 // TODO pool file names
317 // TODO encoding of filenames?
332 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) { 318 while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) {
333 _files.add(new String(data, lastStart, breakIndex4 - lastStart)); 319 _files.add(new String(data, lastStart, breakIndex4 - lastStart));
334 lastStart = breakIndex4 + 1; 320 lastStart = breakIndex4 + 1;
335 if (data[breakIndex4 + 1] == lineBreak) { 321 if (data[breakIndex4 + 1] == lineBreak) {
336 // found \n\n 322 // found \n\n
360 this.time = _time; 346 this.time = _time;
361 this.timezone = _timezone; 347 this.timezone = _timezone;
362 this.files = _files == null ? Collections.<String> emptyList() : Collections.unmodifiableList(_files); 348 this.files = _files == null ? Collections.<String> emptyList() : Collections.unmodifiableList(_files);
363 this.comment = _comment; 349 this.comment = _comment;
364 this.extras = _extrasMap; 350 this.extras = _extrasMap;
351 }
352
353 private Map<String, String> parseExtras(String _extras) {
354 final String extras_branch_key = "branch";
355 _extras = _extras == null ? null : _extras.trim();
356 if (_extras == null || _extras.length() == 0) {
357 return Collections.singletonMap(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME);
358 }
359 Map<String, String> _extrasMap = new HashMap<String, String>();
360 int lastIndex = 0;
361 do {
362 String pair;
363 int sp = _extras.indexOf('\0', lastIndex);
364 if (sp == -1) {
365 sp = _extras.length();
366 }
367 if (sp > lastIndex) {
368 pair = _extras.substring(lastIndex, sp);
369 pair = decode(pair);
370 int eq = pair.indexOf(':');
371 _extrasMap.put(pair.substring(0, eq), pair.substring(eq + 1));
372 lastIndex = sp + 1;
373 }
374 } while (lastIndex < _extras.length());
375 if (!_extrasMap.containsKey(extras_branch_key)) {
376 _extrasMap.put(extras_branch_key, HgRepository.DEFAULT_BRANCH_NAME);
377 }
378 return Collections.unmodifiableMap(_extrasMap);
365 } 379 }
366 380
367 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) { 381 private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) {
368 for (int i = startOffset; i < endIndex; i++) { 382 for (int i = startOffset; i < endIndex; i++) {
369 if (src[i] == what) { 383 if (src[i] == what) {