When working with data structures, especially ropes and collections, avoid algorithms that result in quadratic time complexity when linear alternatives exist. Common patterns to watch for include repeated indexing operations and nested loops over related data sets.

Key anti-patterns:

Better approaches:

Example transformation:

// Inefficient O(W*log(N)) - repeated rope indexing
let start = (0..=cursor_char)
    .rev()
    .find(|&i| !is_word(text.char(i)))
    .map(|i| i + 1)
    .unwrap_or(0);

// Efficient O(log(N)+W) - iterator-based
let start = cursor_char - text.chars_at(cursor_char)
    .reversed()
    .take_while(|&c| is_word(c))
    .count();

Always consider the complexity of your algorithm, especially when dealing with text processing, search operations, or nested data access patterns.