perf: aplicar checks performance-* (91 fixes)
Cambios aplicados: - Reemplazar std::endl con '\n' (91 casos) * std::endl hace flush del buffer (más lento) * '\n' solo inserta newline (más rápido) * Mejora rendimiento de logging/debug Check excluido: - performance-enum-size: Tamaño de enum no es crítico para rendimiento
This commit is contained in:
@@ -21,7 +21,7 @@ bool Shape::carregar(const std::string& filepath) {
|
||||
// Llegir fitxer
|
||||
std::ifstream file(filepath);
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "[Shape] Error: no es pot obrir " << filepath << std::endl;
|
||||
std::cerr << "[Shape] Error: no es pot obrir " << filepath << '\n';
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
try {
|
||||
escala_defecte_ = std::stof(extract_value(line));
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: escala invàlida, usant 1.0" << std::endl;
|
||||
std::cerr << "[Shape] Warning: escala invàlida, usant 1.0" << '\n';
|
||||
escala_defecte_ = 1.0F;
|
||||
}
|
||||
} else if (starts_with(line, "center:")) {
|
||||
@@ -66,7 +66,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
primitives_.push_back({PrimitiveType::POLYLINE, points});
|
||||
} else {
|
||||
std::cerr << "[Shape] Warning: polyline amb menys de 2 punts ignorada"
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
}
|
||||
} else if (starts_with(line, "line:")) {
|
||||
auto points = parse_points(extract_value(line));
|
||||
@@ -74,14 +74,14 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
primitives_.push_back({PrimitiveType::LINE, points});
|
||||
} else {
|
||||
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 punts"
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
// Comandes desconegudes ignorades silenciosament
|
||||
}
|
||||
|
||||
if (primitives_.empty()) {
|
||||
std::cerr << "[Shape] Error: cap primitiva carregada" << std::endl;
|
||||
std::cerr << "[Shape] Error: cap primitiva carregada" << '\n';
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ void Shape::parse_center(const std::string& value) {
|
||||
centre_.x = std::stof(trim(val.substr(0, comma)));
|
||||
centre_.y = std::stof(trim(val.substr(comma + 1)));
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: centre invàlid, usant (0,0)" << std::endl;
|
||||
std::cerr << "[Shape] Warning: centre invàlid, usant (0,0)" << '\n';
|
||||
centre_ = {.x = 0.0F, .y = 0.0F};
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ std::vector<Punt> Shape::parse_points(const std::string& str) const {
|
||||
points.push_back({x, y});
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: punt invàlid ignorat: " << pair
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
// Check cache first
|
||||
auto it = cache_.find(filename);
|
||||
if (it != cache_.end()) {
|
||||
std::cout << "[ShapeLoader] Cache hit: " << filename << std::endl;
|
||||
std::cout << "[ShapeLoader] Cache hit: " << filename << '\n';
|
||||
return it->second; // Cache hit
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||
if (data.empty()) {
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << normalized
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -42,19 +42,19 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
auto shape = std::make_shared<Shape>();
|
||||
if (!shape->parsejar_fitxer(file_content)) {
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Verify shape is valid
|
||||
if (!shape->es_valida()) {
|
||||
std::cerr << "[ShapeLoader] Error: forma invàlida " << normalized << std::endl;
|
||||
std::cerr << "[ShapeLoader] Error: forma invàlida " << normalized << '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Cache and return
|
||||
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->get_nom()
|
||||
<< ", " << shape->get_num_primitives() << " primitives)" << std::endl;
|
||||
<< ", " << shape->get_num_primitives() << " primitives)" << '\n';
|
||||
|
||||
cache_[filename] = shape;
|
||||
return shape;
|
||||
@@ -62,7 +62,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
|
||||
void ShapeLoader::clear_cache() {
|
||||
std::cout << "[ShapeLoader] Netejant caché (" << cache_.size() << " formes)"
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
cache_.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
shape_estrella_ = ShapeLoader::load("star.shp");
|
||||
|
||||
if (!shape_estrella_ || !shape_estrella_->es_valida()) {
|
||||
std::cerr << "ERROR: No s'ha pogut carregar star.shp" << std::endl;
|
||||
std::cerr << "ERROR: No s'ha pogut carregar star.shp" << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ void VectorText::load_charset() {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ void VectorText::load_charset() {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ void VectorText::load_charset() {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,12 +72,12 @@ void VectorText::load_charset() {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "[VectorText] Carregats " << chars_.size() << " caràcters"
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
std::string VectorText::get_shape_filename(char c) const {
|
||||
@@ -230,7 +230,7 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
|
||||
} else {
|
||||
// Carácter no soportado: saltar (o renderizar '?' en el futuro)
|
||||
std::cerr << "[VectorText] Warning: caràcter no suportat '" << c << "'"
|
||||
<< std::endl;
|
||||
<< '\n';
|
||||
current_x += char_width_scaled + spacing_scaled;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user