Performance improvement

Igor Mironchik igor.mironchik at gmail.com
Thu May 22 18:39:34 BST 2025


>> Hi.
>>
>> I'd like to ask you, guys, maybe I'm a dumb a little, and you know how
>> to optimize a following function.
> I don't understand the requirements.
> Can you provide 10 sets of input/output ?


1) U+0009 U+0020 U+2008 abbc

      skipIf(0, line, [](const QChar &ch){ return ch.isSpace(); }); // 
Should return 3.

      skipIf(3, line, [](const QChar &ch){ return ch.isSpace(); }); // 
Should return 3.

2) ab1234567890abcd

skipIf(2, line, [](const QChar &ch){ return ch.isDigit(); }); // Should 
return 12.

skipIf(0, line, [](const QChar &ch){ return ch.isDigit(); }); // Should 
return 0.

skipIf(12, line, [](const QChar &ch){ return ch.isDigit(); }); // Should 
return 12.

3) U+0020 U+0020 ~~~

const auto skipCh = QLatin1Char('~');

skipIf(0, line, [&skipCh](const QChar &ch){ return (ch == skipCh); }) ; 
// Should return 0.

skipIf(2, line, [&skipCh](const QChar &ch){ return (ch == skipCh); }) ; 
// Should return 5.

4) gmail

auto isAllowed = [](const QChar &ch) -> bool { const auto unicode = 
ch.unicode(); return ((unicode >= 48 && unicode <= 57) || (unicode >= 97 
&& unicode <= 122) || (unicode >= 65 && unicode <= 90)); }; auto 
isAdditional = [](const QChar &ch) -> bool { const auto unicode = 
ch.unicode(); return (unicode == 33 || (unicode >= 35 && unicode <= 39) 
|| unicode == 42 || unicode == 43 || (unicode >= 45 && unicode <= 47) || 
unicode == 61 || unicode == 63 || (unicode >= 94 && unicode <= 96) || 
(unicode >= 123 && unicode <= 126)); };

skipIf(0, line, [&isAllowed, &isAdditional](const QChar &ch){ return 
(isAllowed(ch) || isAdditional(ch)); }); // Should return 5.

skipIf(1, line, [&isAllowed, &isAdditional](const QChar &ch){ return 
(isAllowed(ch) || isAdditional(ch)); }); // Should return 5.

5) {abc}

const auto fch = QLatin1Char('}');

skipIf(0, line, [&fch](const QChar &ch){ return (ch != fch); }) ; // 
Should return 4.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-devel/attachments/20250522/62669f84/attachment.htm>


More information about the kde-devel mailing list