@@ -598,29 +598,34 @@ _parse_color_from_text(PyObject *str_obj, Uint8 *rgba)
598
598
/* We assume the caller handled this check for us. */
599
599
assert (PyUnicode_Check (str_obj ));
600
600
601
- name1 = PyObject_CallMethod (str_obj , "replace" , "(ss)" , " " , "" );
602
- if (!name1 ) {
603
- return -1 ;
604
- }
605
- name2 = PyObject_CallMethod (name1 , "lower" , NULL );
606
- Py_DECREF (name1 );
607
- if (!name2 ) {
608
- return -1 ;
609
- }
610
- color = PyDict_GetItem (_COLORDICT , name2 );
611
- Py_DECREF (name2 );
601
+ color = PyDict_GetItem (_COLORDICT ,
602
+ str_obj ); // optimize for correct color names
612
603
if (!color ) {
613
- switch (_hexcolor (str_obj , rgba )) {
614
- case TRISTATE_FAIL :
615
- PyErr_SetString (PyExc_ValueError , "invalid color name" );
616
- return -1 ;
617
- case TRISTATE_ERROR :
618
- return -1 ;
619
- default :
620
- break ;
604
+ name1 = PyObject_CallMethod (str_obj , "replace" , "(ss)" , " " , "" );
605
+ if (!name1 ) {
606
+ return -1 ;
607
+ }
608
+ name2 = PyObject_CallMethod (name1 , "lower" , NULL );
609
+ Py_DECREF (name1 );
610
+ if (!name2 ) {
611
+ return -1 ;
612
+ }
613
+ color = PyDict_GetItem (_COLORDICT , name2 );
614
+ Py_DECREF (name2 );
615
+ if (!color ) {
616
+ switch (_hexcolor (str_obj , rgba )) {
617
+ case TRISTATE_FAIL :
618
+ PyErr_SetString (PyExc_ValueError , "invalid color name" );
619
+ return -1 ;
620
+ case TRISTATE_ERROR :
621
+ return -1 ;
622
+ default :
623
+ return 0 ;
624
+ }
621
625
}
622
626
}
623
- else if (!pg_RGBAFromObjEx (color , rgba , PG_COLOR_HANDLE_RESTRICT_SEQ )) {
627
+
628
+ if (!pg_RGBAFromObjEx (color , rgba , PG_COLOR_HANDLE_RESTRICT_SEQ )) {
624
629
PyErr_Format (PyExc_RuntimeError ,
625
630
"internal pygame error - colordict is supposed to "
626
631
"only have tuple values, but there is an object of "
0 commit comments