Repository: godotengine/godot (language: cpp)

Issue:
Optimize `Color::to_html` by allocating less.
Just something quick I came across while trying to get rid of `String(char *)`.

The function used to allocate a lot, now it allocates less.

## Benchmark

It's probably not important, but just for completion's sake: it's about 18x faster than before.
```
	{
		auto t0 = std::chrono::high_resolution_clock::now();
		for (int i = 0; i < 20000000; i ++) {
			c.to_html();
		}
		auto t1 = std::chrono::high_resolution_clock::now();
		std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count() << "ms\n";
	}
```

- `10636ms` on master
- `591ms` on this PR


Discussion / hints:
Thanks!

Fix patch:
diff --git a/core/math/color.cpp b/core/math/color.cpp
index d75a33f6a152..699d414cc955 100644
--- a/core/math/color.cpp
+++ b/core/math/color.cpp
@@ -113,10 +113,8 @@ void _append_hex(float p_val, char32_t *string) {
 	int v = Math::round(p_val * 255.0f);
 	v = CLAMP(v, 0, 255);
 
-	for (int i = 0; i < 2; i++) {
-		string[i] = hex_char_table_lower[v & 0xF];
-		v >>= 4;
-	}
+	string[0] = hex_char_table_lower[(v >> 4) & 0xF];
+	string[1] = hex_char_table_lower[v & 0xF];
 }
 
 String Color::to_html(bool p_alpha) const {


Test patch: