Skip to content

Commit

Permalink
Use Tk_AllocColorFromObj() in stead of Tk_GetColor() where possible: …
Browse files Browse the repository at this point in the history
…it's more efficient (see documentation)
  • Loading branch information
jan.nijtmans committed Sep 7, 2024
2 parents d1f1f07 + abe6a2e commit dc6a2c4
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion generic/tk.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ typedef struct Tk_Outline {
Tk_Dash dash; /* Dash pattern. */
Tk_Dash activeDash; /* Dash pattern if state is active. */
Tk_Dash disabledDash; /* Dash pattern if state is disabled. */
Tcl_Obj *offsetObj; /* Dash offset. */
Tcl_Obj *offsetObj; /* Dash offset. */
void *reserved2; /* Reserved for future expansion. */
void *reserved3;
Tk_TSOffset tsoffset; /* Stipple offset for outline. */
Expand Down
4 changes: 2 additions & 2 deletions generic/tkCmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1776,11 +1776,11 @@ Tk_WinfoObjCmd(
{
Colormap temp = Tk_Colormap(tkwin);
Tk_Colormap(tkwin) = TK_DYNAMIC_COLORMAP;
colorPtr = Tk_GetColor(interp, tkwin, Tcl_GetString(objv[3]));
colorPtr = Tk_AllocColorFromObj(interp, tkwin, objv[3]);
Tk_Colormap(tkwin) = temp;
}
#else
colorPtr = Tk_GetColor(interp, tkwin, Tcl_GetString(objv[3]));
colorPtr = Tk_AllocColorFromObj(interp, tkwin, objv[3]);
#endif
if (colorPtr == NULL) {
return TCL_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions generic/tkImgPhoto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1668,8 +1668,8 @@ ParseSubcommandOptions(
goto oneValueRequired;
}
*optIndexPtr = ++index;
optPtr->background = Tk_GetColor(interp, Tk_MainWindow(interp),
Tcl_GetString(objv[index]));
optPtr->background = Tk_AllocColorFromObj(interp, Tk_MainWindow(interp),
objv[index]);
if (!optPtr->background) {
return TCL_ERROR;
}
Expand Down
2 changes: 1 addition & 1 deletion macosx/tkMacOSXDialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Tk_ChooseColorObjCmd(
case COLOR_INITIAL: {
XColor *colorPtr;

colorPtr = Tk_GetColor(interp, tkwin, value);
colorPtr = Tk_AllocColorFromObj(interp, tkwin, objv[i + 1]);
if (colorPtr == NULL) {
goto end;
}
Expand Down
3 changes: 1 addition & 2 deletions unix/tkUnixScrlbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ TkpDisplayScrollbar(
XPoint points[7];
Tk_3DBorder border;
int relief, width, elementBorderWidth;
int highlightWidth;
int borderWidth, highlightWidth;
Pixmap pixmap;
int borderWidth;

if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
goto done;
Expand Down
2 changes: 1 addition & 1 deletion win/tkWinDialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ Tk_ChooseColorObjCmd(
case COLOR_INITIAL: {
XColor *colorPtr;

colorPtr = Tk_GetColor(interp, tkwin, string);
colorPtr = Tk_AllocColorFromObj(interp, tkwin, valuePtr);
if (colorPtr == NULL) {
return TCL_ERROR;
}
Expand Down
4 changes: 2 additions & 2 deletions win/tkWinWm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3070,7 +3070,7 @@ WmAttributesCmd(
}
wmPtr->alpha = dval;
} else { /* -transparentcolor */
const char *crefstr = Tcl_GetStringFromObj(objv[i+1], &length);
(void)Tcl_GetStringFromObj(objv[i+1], &length);

if (length == 0) {
/* reset to no transparent color */
Expand All @@ -3080,7 +3080,7 @@ WmAttributesCmd(
}
} else {
XColor *cPtr =
Tk_GetColor(interp, tkwin, crefstr);
Tk_AllocColorFromObj(interp, tkwin, objv[i+1]);
if (cPtr == NULL) {
return TCL_ERROR;
}
Expand Down

0 comments on commit dc6a2c4

Please sign in to comment.