Commit 8a5c1d3d authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Atoms.c: some code cleanup

add else clauses, improve debugging, add comments
parent 2594ca99
...@@ -610,17 +610,14 @@ static AtomMap* nxagentFindAtomByName(char *string, unsigned int length) ...@@ -610,17 +610,14 @@ static AtomMap* nxagentFindAtomByName(char *string, unsigned int length)
* really asking to X-server and caching them. * really asking to X-server and caching them.
* FIXME: I don't really know if is better to allocate * FIXME: I don't really know if is better to allocate
* an automatic variable like ret_value and write it, instead of make all * an automatic variable like ret_value and write it, instead of make all
* these return!, perhaps this way the code is a little bit easyer to read. * these return!, perhaps this way the code is a little bit easier to read.
* I think this and the 2 .*Find.* are the only functions to look for performances. * I think this and the 2 .*Find.* are the only functions to look for performances.
*/ */
XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
{ {
AtomMap *current;
/* /*
* Surely MakeAtom is faster than * Surely MakeAtom is faster than our nxagentFindAtomByName.
* our nxagentFindAtomByName.
*/ */
Atom local = MakeAtom(string, length, Makeit); Atom local = MakeAtom(string, length, Makeit);
...@@ -635,6 +632,8 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -635,6 +632,8 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
return local; return local;
} }
AtomMap *current;
if ((current = nxagentFindAtomByLocalValue(local))) if ((current = nxagentFindAtomByLocalValue(local)))
{ {
/* /*
...@@ -643,8 +642,7 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -643,8 +642,7 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
return current->remote; return current->remote;
} }
else if ((current = nxagentFindAtomByName(string, length)))
if ((current = nxagentFindAtomByName(string, length)))
{ {
/* /*
* Found cached by name. * Found cached by name.
...@@ -656,27 +654,30 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -656,27 +654,30 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
return current->remote; return current->remote;
} }
else
{
/* /*
* We really have to ask the Xserver for it. * We really have to ask the Xserver for it.
*/ */
{ /* FIXME: why is Makeit inverted here? */
XlibAtom remote = XInternAtom(nxagentDisplay, string, !Makeit); XlibAtom remote = XInternAtom(nxagentDisplay, string, !Makeit);
if (remote == None) if (remote == None)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentMakeAtom: WARNING XInternAtom failed.\n"); fprintf(stderr, "nxagentMakeAtom: WARNING XInternAtom(.., %s, ..) failed.\n", string);
#endif #endif
return None; return None;
} }
else
{
nxagentWriteAtom(local, remote, string, True); nxagentWriteAtom(local, remote, string, True);
return remote; return remote;
} }
}
} }
XlibAtom nxagentLocalToRemoteAtom(Atom local) XlibAtom nxagentLocalToRemoteAtom(Atom local)
...@@ -693,6 +694,7 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local) ...@@ -693,6 +694,7 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local)
return None; return None;
} }
/* no mapping required for built-in atoms */
if (local <= XA_LAST_PREDEFINED) if (local <= XA_LAST_PREDEFINED)
{ {
#ifdef DEBUG #ifdef DEBUG
...@@ -705,14 +707,20 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local) ...@@ -705,14 +707,20 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local)
if (current) if (current)
{ {
#ifdef TEST #ifdef DEBUG
if (current->string)
fprintf(stderr, "%s: local [%d] -> remote [%d (%s)]\n", __func__, local, current->remote, current->string);
else
fprintf(stderr, "%s: local [%d] -> remote [%d]\n", __func__, local, current->remote); fprintf(stderr, "%s: local [%d] -> remote [%d]\n", __func__, local, current->remote);
#endif #endif
return current->remote; return current->remote;
} }
else
{
const char *string = NameForAtom(local); const char *string = NameForAtom(local);
/* FIXME: why False? */
XlibAtom remote = XInternAtom(nxagentDisplay, string, False); XlibAtom remote = XInternAtom(nxagentDisplay, string, False);
if (remote == None) if (remote == None)
...@@ -727,10 +735,11 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local) ...@@ -727,10 +735,11 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local)
nxagentWriteAtom(local, remote, string, True); nxagentWriteAtom(local, remote, string, True);
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: local [%d] -> remote [%d (%s)]\n", __func__, local, remote, string); fprintf(stderr, "%s: local [%d (%s)] -> remote [%d]\n", __func__, local, string, remote);
#endif #endif
return remote; return remote;
}
} }
Atom nxagentRemoteToLocalAtom(XlibAtom remote) Atom nxagentRemoteToLocalAtom(XlibAtom remote)
...@@ -743,6 +752,7 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote) ...@@ -743,6 +752,7 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote)
return None; return None;
} }
/* no mapping required for built-in atoms */
if (remote <= XA_LAST_PREDEFINED) if (remote <= XA_LAST_PREDEFINED)
{ {
#ifdef DEBUG #ifdef DEBUG
...@@ -774,11 +784,16 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote) ...@@ -774,11 +784,16 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote)
} }
#ifdef DEBUG #ifdef DEBUG
if (current->string)
fprintf(stderr, "%s: remote [%d] -> local [%d (%s)]\n", __func__, remote, current->local, current->string);
else
fprintf(stderr, "%s: remote [%d] -> local [%d]\n", __func__, remote, current->local); fprintf(stderr, "%s: remote [%d] -> local [%d]\n", __func__, remote, current->local);
#endif #endif
return current->local; return current->local;
} }
else
{
char *string = XGetAtomName(nxagentDisplay, remote); char *string = XGetAtomName(nxagentDisplay, remote);
if (string) if (string)
...@@ -809,6 +824,7 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote) ...@@ -809,6 +824,7 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote)
#endif #endif
return None; return None;
}
} }
#ifdef DEBUG #ifdef DEBUG
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment