pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/4] gui: Factor out duplicated code for executing and pastin


From: John Darrington
Subject: Re: [PATCH 4/4] gui: Factor out duplicated code for executing and pasting syntax.
Date: Sun, 5 Dec 2010 12:03:31 +0000
User-agent: Mutt/1.5.18 (2008-05-17)

On Sat, Dec 04, 2010 at 11:37:38AM -0800, Ben Pfaff wrote:

     Reducing code duplication is good on its own.  This will also make it
     easier in upcoming patches to swap out "getl_interface" with a new
     structure, by eliminating most of the references to getl_interface.

     +/* Executes null-terminated string SYNTAX as syntax.
     +   Returns SYNTAX. */
     +gchar *
     +execute_syntax_string (gchar *syntax)
     +{
     +  struct getl_interface *sss = create_syntax_string_source (syntax);
     +  execute_syntax (sss);
     +  return syntax;
     +}
     +
     +/* Executes null-terminated string SYNTAX as syntax.
     +   Returns SYNTAX. */
     +const gchar *
     +execute_const_syntax_string (const gchar *syntax)
     +{
     +  return execute_syntax_string (CONST_CAST (gchar *, syntax));
     +}

These functions can be written as:

/* Executes null-terminated string SYNTAX as syntax.
   Returns SYNTAX. */
gchar *
execute_syntax_string (gchar *syntax)
{
  execute_const_syntax_string (syntax);
  return syntax;
}

/* Executes null-terminated string SYNTAX as syntax.
   Returns SYNTAX. */
const gchar *
execute_const_syntax_string (const gchar *syntax)
{
  execute_syntax (create_syntax_string_source (syntax));
  return syntax;
}


.. which avoids the CONST_CAST, and a reference to getl_interface.
Optionally, you could make the second function return void, since
nowhere is its return value used.

J'

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.


Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]