https://bugs.documentfoundation.org/show_bug.cgi?id=147132

            Bug ID: 147132
           Summary: Flatten Basic function implementations
           Product: LibreOffice
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
          Severity: enhancement
          Priority: lowest
         Component: LibreOffice
          Assignee: [email protected]
          Reporter: [email protected]

In basic/source/runtime/methods.cxx, there are lots of SbRtl_* functions, that
implement various Basic functions and procedures. They typically have an
argument check, and do the actual work in 'else' branch of the check.

This easyhack is to flatten those functions to increase readability, by
returning from the failed check.

For example:

void SbRtl_Tan(StarBASIC *, SbxArray & rPar, bool)
{
    if (rPar.Count() < 2)
    {
        StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
    }
    else
    {
        SbxVariableRef pArg = rPar.Get(1);
        rPar.Get(0)->PutDouble(tan(pArg->GetDouble()));
    }
}

This function may be re-written as

void SbRtl_Tan(StarBASIC *, SbxArray & rPar, bool)
{
    if (rPar.Count() < 2)
        return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );

    SbxVariableRef pArg = rPar.Get(1);
    rPar.Get(0)->PutDouble(tan(pArg->GetDouble()));
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to