Changeset View
Changeset View
Standalone View
Standalone View
src/buffer/katetextbuffer.cpp
Show First 20 Lines • Show All 425 Lines • ▼ Show 20 Line(s) | 422 | { | |||
---|---|---|---|---|---|
426 | } | 426 | } | ||
427 | 427 | | |||
428 | // we need blocks and last used block should not be negative | 428 | // we need blocks and last used block should not be negative | ||
429 | Q_ASSERT(!m_blocks.isEmpty()); | 429 | Q_ASSERT(!m_blocks.isEmpty()); | ||
430 | Q_ASSERT(m_lastUsedBlock >= 0); | 430 | Q_ASSERT(m_lastUsedBlock >= 0); | ||
431 | 431 | | |||
432 | /** | 432 | /** | ||
433 | * shortcut: try last block first | 433 | * shortcut: try last block first | ||
434 | * cache m_lastUsedBlock's value to avoid race conditions | ||||
434 | */ | 435 | */ | ||
435 | if (m_lastUsedBlock < m_blocks.size()) { | 436 | int lastUsedBlock = m_lastUsedBlock; | ||
437 | if (lastUsedBlock < m_blocks.size()) { | ||||
436 | /** | 438 | /** | ||
437 | * check if block matches | 439 | * check if block matches | ||
438 | * if yes, just return again this block | 440 | * if yes, just return again this block | ||
439 | */ | 441 | */ | ||
440 | TextBlock *block = m_blocks[m_lastUsedBlock]; | 442 | TextBlock *block = m_blocks[lastUsedBlock]; | ||
441 | const int start = block->startLine(); | 443 | const int start = block->startLine(); | ||
442 | const int lines = block->lines(); | 444 | const int lines = block->lines(); | ||
443 | if (start <= line && line < (start + lines)) { | 445 | if (start <= line && line < (start + lines)) { | ||
444 | return m_lastUsedBlock; | 446 | return lastUsedBlock; | ||
445 | } | 447 | } | ||
446 | } | 448 | } | ||
447 | 449 | | |||
448 | /** | 450 | /** | ||
449 | * search for right block | 451 | * search for right block | ||
450 | * use binary search | 452 | * use binary search | ||
451 | * if we leave this loop not by returning the found element we have an error | 453 | * if we leave this loop not by returning the found element we have an error | ||
452 | */ | 454 | */ | ||
▲ Show 20 Lines • Show All 618 Lines • Show Last 20 Lines |