perf(send): poll the clipboard for the paste hint only when it helps
The send tab read the OS clipboard every frame the paste button was hovered, to preview a pasted address. SDL's clipboard read is a synchronous round-trip that can stall, and the preview can only ever latch when the recipient field is empty, so most of those reads were wasted work. - The clipboard is now read only while the button is hovered and the recipient field is empty, polled once on hover entry and then at most twice a second. - Trimming the clipboard text moves to a shared helper that also bounds the copy so a pathological multi-megabyte clipboard is ignored. Tests: the trim helper handles null, surrounding whitespace, an all-whitespace string, and the length bound. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -118,5 +118,18 @@ bool containsIgnoreCase(std::string_view haystack, std::string_view needle)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string trimmedClipboardText(const char* clip, std::size_t maxBytes)
|
||||
{
|
||||
if (!clip || clip[0] == '\0') return {};
|
||||
std::size_t n = 0;
|
||||
while (n <= maxBytes && clip[n] != '\0') ++n;
|
||||
if (n > maxBytes) return {};
|
||||
const auto ws = [](char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r'; };
|
||||
std::size_t b = 0, e = n;
|
||||
while (b < e && ws(clip[b])) ++b;
|
||||
while (e > b && ws(clip[e - 1])) --e;
|
||||
return std::string(clip + b, e - b);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace dragonx
|
||||
|
||||
@@ -82,5 +82,9 @@ std::string truncateMiddleToFit(const std::string& s, int minFront, int minBack,
|
||||
return build(lo);
|
||||
}
|
||||
|
||||
// Clipboard text -> trimmed (ASCII whitespace ' ', \t, \n, \r) candidate string. Empty for a null/empty clip or one
|
||||
// longer than maxBytes (an address is < 100 bytes; this bounds the copy of a pathological multi-MB clipboard).
|
||||
std::string trimmedClipboardText(const char* clip, std::size_t maxBytes = 1024);
|
||||
|
||||
} // namespace util
|
||||
} // namespace dragonx
|
||||
|
||||
Reference in New Issue
Block a user