Difference between revisions of "User:Ksuzee/Proposal"

From BRL-CAD
Line 21: Line 21:
 
     * strcmp() from crashing.
 
     * strcmp() from crashing.
 
     */
 
     */
     if (string1)
+
     if (string1) s1 = string1;
s1 = string1;
+
     if (string2) s2 = string2;
     if (string2)
 
s2 = string2;
 
 
     return strcmp(s1, s2);
 
     return strcmp(s1, s2);
 
   }
 
   }
Line 48: Line 46:
 
     return strncasecmp(s1, s2, n);
 
     return strncasecmp(s1, s2, n);
 
   }
 
   }
 +
 
   These functions are situated in file src/libbu/str.c. All these functions have the same bodies. So I propose to change these four functions and have function with such body:
 
   These functions are situated in file src/libbu/str.c. All these functions have the same bodies. So I propose to change these four functions and have function with such body:
 +
 
   int
 
   int
 
   bu_strcmp(const char *string1, const char *string2, size_t n, unsigned char cases_cmp)
 
   bu_strcmp(const char *string1, const char *string2, size_t n, unsigned char cases_cmp)
Line 57: Line 57:
 
     * strncmp() from crashing.
 
     * strncmp() from crashing.
 
     */
 
     */
     if (string1)
+
     if (string1) s1 = string1;
s1 = string1;
+
     if (string2) s2 = string2;
     if (string2)
 
s2 = string2;
 
 
     if (cases_cmp)
 
     if (cases_cmp)
 
     {
 
     {
if (n == 0)
+
if (n == 0) return strncasecmp(s1, s2);
return strncasecmp(s1, s2);
 
 
         return strncasecmp(s1, s2, n);
 
         return strncasecmp(s1, s2, n);
 
     }
 
     }
     if (n == 0)
+
     if (n == 0) return strcmp(s1, s2);
return strcmp(s1, s2);
 
 
     return strncmp(s1, s2, n);
 
     return strncmp(s1, s2, n);
 
   }
 
   }
 +
 
The next step is to find functions' calls and correct them
 
The next step is to find functions' calls and correct them
  

Revision as of 08:54, 2 April 2012

Project title

Code Reduction

Brief summary

BRL-CAD has the really huge project. There are a lot of libraries and different files, so there is such problem as code duplication. The sources must be cleaner and smaller. The code must be easy to read and understandable. This reduction will help new developers to make their work more effective and faster. So, the main aim is to shorten the count of lines of code without disrupting the project. Special tests will help not to disrupt the project after reduction.

Detailed description

I decided to choose this project, because, I am sure, I have enough knowledge in c/c++ for doing it. I've been working with it since 19.03.2012. Unfortunately I have a lot of subjects (about 12) this year, so I don't have enough time for working with BRL-CAD and patches every day. Nevertheless, after the 1-5 of May I will be absolutely free and ready to work hard.

Proposes for reduction

BRL-CAD has quite useful Virtual Machine, which helped me to do my first steps with it. Mentor Sean helped me to become quite familiar with it. After several tests with "Simian" I understood that the work for reduction will be really huge. There are a lot of duplications (e.g. just copy-pasts). After testing I can propose such ideas:

  • Duplication in one file.
 Example:
 int
 bu_strcmp(const char *string1, const char *string2)
 {
   const char *s1 = "";
   const char *s2 = "";
   /* "" and NULL are considered equivalent which helps prevent
    * strcmp() from crashing.
    */
   if (string1) s1 = string1;
   if (string2) s2 = string2;
   return strcmp(s1, s2);
 }
 int
 bu_strncmp(const char *string1, const char *string2, size_t n)
 {
   /* the same body */
   return strncmp(s1, s2, n);
 }
 int
 bu_strcasecmp(const char *string1, const char *string2)
 {
   /* the same body */
   return strcasecmp(s1, s2);
 }
 int
 bu_strncasecmp(const char *string1, const char *string2, size_t n)
 {
   /* the same body */
   return strncasecmp(s1, s2, n);
 }
 These functions are situated in file src/libbu/str.c. All these functions have the same bodies. So I propose to change these four functions and have function with such body:
 int
 bu_strcmp(const char *string1, const char *string2, size_t n, unsigned char cases_cmp)
 {
   const char *s1 = "";
   const char *s2 = "";
   /* "" and NULL are considered equivalent which helps prevent
    * strncmp() from crashing.
    */
   if (string1) s1 = string1;
   if (string2) s2 = string2;
   if (cases_cmp)
   {

if (n == 0) return strncasecmp(s1, s2);

       return strncasecmp(s1, s2, n);	
   }
   if (n == 0) return strcmp(s1, s2);
   return strncmp(s1, s2, n);
 }

The next step is to find functions' calls and correct them

  • Duplication in one directory but different files

In such situation I suggest to make file like "utils.c" which would be common for this directory. I have already done the patch for such situation: my first patch

  • Duplication in different directories

Such duplication must be the most careful and difficult, because every change can influence working the whole project. Common functions will be situated in the libraries.

Tests and patches

I am sure, it is necessary to make tests as much as possible to avoid mistakes or to find them before big changes. I think that simple unit tests would be the best way in this situation.

As for patches, I think, they must be doing very often during the whole period of working for the same reason as tests.

Simian

I think the tool "Simian" is really useful and easy in use. Also it works rather fast. If I am involved into this project I want to use it specifically. But, of course, if my mentor advises me something else, I will improve my skills in other tool