perf: include() parametresini std::string → std::string_view yap

Tokenizer her token için ~84 kez include() çağırıyor.
Önceki imza std::string (değer kopyası) aldığından her çağrıda
heap allocation yapılıyordu. string_view + explicit std::string()
cast'larının kaldırılmasıyla 2.3 MB dosyada tokens süresi
17.6s → 11.9s (−32%).

Kök neden: src/tokenizer/tokenizer.cpp satır 44/61/73'teki
std::string(kw/del/op) explicit cast'ları string_view tablolardan
gereksiz kopya üretiyordu.
This commit is contained in:
saqut 2026-06-18 18:03:54 +03:00
parent 60870aef8e
commit d82fe6b703
5 changed files with 38 additions and 5 deletions

Binary file not shown.

View File

@ -21,3 +21,35 @@
1 3534 1781792355631085471 CMakeFiles/saqut.dir/src/semantic/type_checker.cpp.o 15f44776b9c3e26d 1 3534 1781792355631085471 CMakeFiles/saqut.dir/src/semantic/type_checker.cpp.o 15f44776b9c3e26d
1 5538 1781792355629691194 CMakeFiles/saqut.dir/src/main.cpp.o 110c26cb1d0c3a23 1 5538 1781792355629691194 CMakeFiles/saqut.dir/src/main.cpp.o 110c26cb1d0c3a23
5538 5861 1781792361166696724 saqut 77cf84e33c34ab02 5538 5861 1781792361166696724 saqut 77cf84e33c34ab02
1 4565 1781794501587748975 CMakeFiles/saqut.dir/src/lexer/lexer.cpp.o 90eeec811f2137e6
6 5765 1781794501593748981 CMakeFiles/saqut.dir/src/parser/parser.cpp.o 2c65b7be26cead32
2 6786 1781794501590384636 CMakeFiles/saqut.dir/src/parser/nodes/statements.cpp.o b5c20724bbf3648c
2 6934 1781794501589760926 CMakeFiles/saqut.dir/src/parser/nodes/binary_expr.cpp.o d2e2bb2f8a63c6d2
2 7059 1781794501590181179 CMakeFiles/saqut.dir/src/parser/nodes/literal.cpp.o 78f2c4da7c9b2281
2 7150 1781794501590288617 CMakeFiles/saqut.dir/src/parser/nodes/program.cpp.o ac5bbcd74d87561a
2 7264 1781794501589877089 CMakeFiles/saqut.dir/src/parser/nodes/declarations.cpp.o b6c56f04a257f685
2 7510 1781794501590069464 CMakeFiles/saqut.dir/src/parser/nodes/identifier.cpp.o eb96bb4b1eb4ad80
2 7889 1781794501589962656 CMakeFiles/saqut.dir/src/parser/nodes/expressions.cpp.o 4057e3d63c63a1ab
2 9281 1781794501588748976 CMakeFiles/saqut.dir/src/main.cpp.o 110c26cb1d0c3a23
4565 9347 1781794506151753299 CMakeFiles/saqut.dir/src/semantic/structural_validator.cpp.o 4bfec8abc0e9893e
6934 9664 1781794508520755543 CMakeFiles/saqut.dir/src/tokenizer/tokenizer.cpp.o a01677f8bb4f4dbc
5765 9917 1781794507351754435 CMakeFiles/saqut.dir/src/semantic/type_checker.cpp.o 15f44776b9c3e26d
6786 10724 1781794508372755403 CMakeFiles/saqut.dir/src/symbol/symbol_collector.cpp.o 3348f498f369213d
10724 10943 1781794512310759133 saqut 77cf84e33c34ab02
1 5577 1781794548935793844 CMakeFiles/saqut.dir/src/lexer/lexer.cpp.o 90eeec811f2137e6
6 7118 1781794548940793848 CMakeFiles/saqut.dir/src/parser/parser.cpp.o 2c65b7be26cead32
1 7401 1781794548937164958 CMakeFiles/saqut.dir/src/parser/nodes/expressions.cpp.o 4057e3d63c63a1ab
1 7781 1781794548937485082 CMakeFiles/saqut.dir/src/parser/nodes/program.cpp.o ac5bbcd74d87561a
5 7795 1781794548939793847 CMakeFiles/saqut.dir/src/parser/nodes/statements.cpp.o b5c20724bbf3648c
1 7846 1781794548937277813 CMakeFiles/saqut.dir/src/parser/nodes/identifier.cpp.o eb96bb4b1eb4ad80
1 8355 1781794548937386639 CMakeFiles/saqut.dir/src/parser/nodes/literal.cpp.o 78f2c4da7c9b2281
1 8623 1781794548937059964 CMakeFiles/saqut.dir/src/parser/nodes/declarations.cpp.o b6c56f04a257f685
1 8702 1781794548936968496 CMakeFiles/saqut.dir/src/parser/nodes/binary_expr.cpp.o d2e2bb2f8a63c6d2
1 9568 1781794548936880430 CMakeFiles/saqut.dir/src/main.cpp.o 110c26cb1d0c3a23
7781 10439 1781794556715801213 CMakeFiles/saqut.dir/src/tokenizer/tokenizer.cpp.o a01677f8bb4f4dbc
5577 10556 1781794554511799126 CMakeFiles/saqut.dir/src/semantic/structural_validator.cpp.o 4bfec8abc0e9893e
7118 11087 1781794556053800586 CMakeFiles/saqut.dir/src/semantic/type_checker.cpp.o 15f44776b9c3e26d
7401 11835 1781794556335800853 CMakeFiles/saqut.dir/src/symbol/symbol_collector.cpp.o 3348f498f369213d
11836 12067 1781794560770805055 saqut 77cf84e33c34ab02
2 1784 1781794795003026937 CMakeFiles/saqut.dir/src/tokenizer/tokenizer.cpp.o a01677f8bb4f4dbc
1784 2001 1781794796785028624 saqut 77cf84e33c34ab02

View File

@ -79,7 +79,7 @@ std::string Lexer::getPositionRange() {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// include: Belirtilen kelime mevcut konumda başlıyor mu? // include: Belirtilen kelime mevcut konumda başlıyor mu?
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
bool Lexer::include(std::string word, bool accept) { bool Lexer::include(std::string_view word, bool accept) {
beginPosition(); beginPosition();
for (size_t i = 0; i < word.size(); i++) { for (size_t i = 0; i < word.size(); i++) {
if (isEnd()) { if (isEnd()) {

View File

@ -22,6 +22,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <string_view>
#include <vector> #include <vector>
#include "core/location.hpp" #include "core/location.hpp"
#include "core/sourcefile.hpp" #include "core/sourcefile.hpp"
@ -67,7 +68,7 @@ public:
std::string getPositionRange(); // Pozisyon aralığındaki metni döndür std::string getPositionRange(); // Pozisyon aralığındaki metni döndür
// --- Desen Eşleme --- // --- Desen Eşleme ---
bool include(std::string word, bool accept = true); bool include(std::string_view word, bool accept = true);
// --- Konum Okuma/Yazma --- // --- Konum Okuma/Yazma ---
int getOffset(); // Mevcut offset'i döndür int getOffset(); // Mevcut offset'i döndür

View File

@ -41,7 +41,7 @@ Token* Tokenizer::scope() {
} }
for (const auto& kw : keywords) { for (const auto& kw : keywords) {
if (hmx.include(std::string(kw), false)) { if (hmx.include(kw, false)) {
char next = hmx.getchar(static_cast<int>(kw.size())); char next = hmx.getchar(static_cast<int>(kw.size()));
if ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z') || if ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z') ||
(next >= '0' && next <= '9') || next == '_' || next == '$') { (next >= '0' && next <= '9') || next == '_' || next == '$') {
@ -58,7 +58,7 @@ Token* Tokenizer::scope() {
} }
for (const auto& del : delimiters) { for (const auto& del : delimiters) {
if (hmx.include(std::string(del), false)) { if (hmx.include(del, false)) {
DelimiterToken* dt = new DelimiterToken(); DelimiterToken* dt = new DelimiterToken();
dt->start = hmx.getOffset(); dt->start = hmx.getOffset();
dt->loc = hmx.getLocation(); dt->loc = hmx.getLocation();
@ -70,7 +70,7 @@ Token* Tokenizer::scope() {
} }
for (const auto& op : operators) { for (const auto& op : operators) {
if (hmx.include(std::string(op), false)) { if (hmx.include(op, false)) {
OperatorToken* ot = new OperatorToken(); OperatorToken* ot = new OperatorToken();
ot->start = hmx.getOffset(); ot->start = hmx.getOffset();
ot->loc = hmx.getLocation(); ot->loc = hmx.getLocation();