Original Post
Hi, This thread will probably qualify me for the geekiest thing I've done in a while ;), but do you think some code does resemble an art form, and if so, what's the prettiest bit of code you've (ever) written? Of course, the prettiness of code is relative to the language of the code itself. Here's a contendor for mine - it's short, to the point and simple - from my operating system, Whitix (although the more I look at it, the less poetic it looks :):
/***********************************************************************
*
* FUNCTION: VmLookupPage
*
* DESCRIPTION: Looks up a page in a vNode by file offset to see if anyone
* has mapped the page already.
*
* PARAMETERS: vNode - vNode that contains the shared list.
* offset - file offset needed.
*
* RETURNS: the virtual page containing the file data.
*
***********************************************************************/
static struct VMMapPage* VmLookupPage(struct VNode* vNode,Offset offset)
{
struct VMMapPage* page;
/* Has anyone else mapped it in? */
if (!vNode || vNode->refs == 1 || ListEmpty(&vNode->sharedList))
return NULL;
/* Loop through the shared list and return the one with the offset we need. */
ListForEachEntry(page,&vNode->sharedList,list)
if (page->offset == offset)
return page;
/* Not found. It will now be mapped in. */
return NULL;
}