classpath-patches
[Top][All Lists]
Advanced

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

Re: [cp-patches] FYI: GdkGraphics fix


From: Mark Wielaard
Subject: Re: [cp-patches] FYI: GdkGraphics fix
Date: Tue, 22 Nov 2005 00:13:37 +0100

Hi Lilian,

On Mon, 2005-11-21 at 17:11 -0500, Lillian Angel wrote:
> I re-implemented this to just use replaceAll. I know it is sometimes
> inefficent, so I added a FIXME. 

This is really, really inefficient. 

> +    // FIXME: Possibly more characters we need to ignore/
> +    // Also, implementation may be inefficent because allocating
> +    // new Strings.
> +    str = Pattern.compile("[\b | \t | \n | \f | \r | \" | 
> \']").matcher(str).replaceAll("");
>      drawString(getFontPeer(), str, x, y);

Firstly if you reuse the same regex Pattern then you should allocate it
once and reuse it. But using a regular expression for this simple
replace is really overkill anyway. You will use the character array of
the string in the native gtk+ code anyway. Then you can easily iterate
over the string and possibly remove any unwanted characters. So I would
propose to just pass the string to the native side and filter it there
after you get the chars from the string. You will have to check whether
you have a copy or not before actually replacing the chars or you'll
have to make a copy, but I expect that most strings don't need filtering
at all so you probably only make one pass of the chars and be done.

Cheers,

Mark





reply via email to

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