Explorar o código

Merge pull request #104885 from MewPurPur/html-validation-optimization

Optimize Color HTML validation
Thaddeus Crews hai 5 meses
pai
achega
21956851ac
Modificáronse 1 ficheiros con 6 adicións e 8 borrados
  1. 6 8
      core/math/color.cpp

+ 6 - 8
core/math/color.cpp

@@ -368,22 +368,20 @@ Color Color::html(const String &p_rgba) {
 bool Color::html_is_valid(const String &p_color) {
 bool Color::html_is_valid(const String &p_color) {
 	String color = p_color;
 	String color = p_color;
 
 
-	if (color.length() == 0) {
+	if (color.is_empty()) {
 		return false;
 		return false;
 	}
 	}
-	if (color[0] == '#') {
-		color = color.substr(1);
-	}
 
 
-	// Check if the amount of hex digits is valid.
+	int current_pos = (color[0] == '#') ? 1 : 0;
 	int len = color.length();
 	int len = color.length();
-	if (!(len == 3 || len == 4 || len == 6 || len == 8)) {
+	int num_of_digits = len - current_pos;
+	if (!(num_of_digits == 3 || num_of_digits == 4 || num_of_digits == 6 || num_of_digits == 8)) {
 		return false;
 		return false;
 	}
 	}
 
 
 	// Check if each hex digit is valid.
 	// Check if each hex digit is valid.
-	for (int i = 0; i < len; i++) {
-		if (_parse_col4(color, i) == -1) {
+	for (int i = current_pos; i < len; i++) {
+		if (!is_hex_digit(p_color[i])) {
 			return false;
 			return false;
 		}
 		}
 	}
 	}