PATCH: code cleanup

Tim Yardley liquid at haveheart.com
Thu Apr 5 22:33:25 UTC 2007


All;

Attached is a patch against the multithreaded branch that cleans up spacing
issues bringing the codebase to a hopefully consistent style.  It also
addresses -Wall warnings, some null checks (a TODO item iirc), and adds
asserts at the top of each function for any use of conn *c without checking
to see if c is NULL first.

Hopefully those asserts are not necessary as we all write perfect code...
Right?  Anyway, that conn object is used and passed around enough that it
should be checked.

Note that there are a couple other areas that could be addressed on an
optimization level.  I addressed a few like multiple assignments to a
variable where not needed, elimination of unused variables, value assignment
at initiation where it made sense, #ifdef where a function wont be used,
etc.

Other things that I noticed that could be addressed but require consensus:
  - optimization of the switch statements to leverage jump tables at
compilation
  - focusing on popular default cases at the top of the switch to reduce
comparisons
  - restructing switch statements if necessary to support that under
different compilers (nesting the switches)
  - visiting the usage of char vs int (byte alignment, powers of two
padding, etc)
  - inlining some of the smaller functions (candidates would include some of
the item funtions, etc)


A couple of the malloc cases in there looked potentially troubling
(arbitrary values chosen, and some potential other misallocations) but I
didn't spend the time to fully analyze them.  Does anyone have access to one
of the commercial source audit applications that would like to run memcached
through it?  If not, would anyone be interested in me persuing that avenue
with some of the vendors that have offered to run their commercial
applications on opensource software?

Feedback welcome.

/tmy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cleanup.patch
Type: text/x-patch
Size: 35901 bytes
Desc: not available
Url : http://lists.danga.com/pipermail/memcached/attachments/20070405/dd3ab261/cleanup-0001.bin


More information about the memcached mailing list