octave-maintainers
[Top][All Lists]
Advanced

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

Re: cleaning up pkg.m


From: Rik
Subject: Re: cleaning up pkg.m
Date: Wed, 14 Mar 2012 10:50:35 -0700

On 03/14/2012 09:48 AM, address@hidden wrote:
> From: "c." <address@hidden>
> > Date: 14 March 2012 13:14:13 GMT+01:00
> > To: S?ren Hauberg <address@hidden>
> > Cc: Thomas Weber <address@hidden>, Jordi Guti?rrez Hermoso <address@hidden>
> > Subject: How to simplify pkg.m (was Re: [OctDev] Patch for the Image package (changed behavior of ismatrix))
> >
> >
> > Indeed functions like "split_by", "split" or "rsplit" could probably eliminated,
> > I'll start looking into it, if someone is willing to help please let me know.
> > c.
> >

I spent a lot of time improving the performance and functionality of the string functions between 3.4.3 and 3.6.0.  I think you should be able to find replacements.  Also, pkg.m is not something called in a tight inner loop so if you just want to use regexp to do your work that would be fine.

You would need to verify but the following look like replacements
strip => strtrim
rstrip => deblank
split_by => strtrim (strsplit ())

I think you could also use the fact that many of the string functions will operate on char arrays or cell arrays of strings.  For example, the isautoload function.

function auto = isautoload (desc)
  auto = false;
  if (isfield (desc{1}, "autoload"))
    a = desc{1}.autoload;
    if ((isnumeric (a) && a > 0)
        || (ischar (a) && (strcmpi (a, "true")
                         || strcmpi (a, "on")
                         || strcmpi (a, "yes")
                         || strcmpi (a, "1"))))
      auto = true;
    endif
  endif
endfunction

The second bit of this could be simplified quite a bit with

ischar (a) && any (strcmpi (a, {"true", "on", "yes", "1"}))

Cheers,
Rik


reply via email to

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