aspose file tools*
The moose likes Java in General and the fly likes a need for speed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "a need for speed" Watch "a need for speed" New topic
Author

a need for speed

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

i just added a flood fill feature to my paint program. it works just fine but it is a bit too slow for my liking. after solving 48 euler project problems, i am thinking there must be a way to speed this up. to flood fill most of the screen on my antique laptop takes about 2 minutes.


SCJP
Visit my download page
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

i solved the problem. i was thinking it was the foreach loop to check each point before adding it to the queue to make sure it is not already there. i was thinking it would be nice if ArrayDeque had a contains() method. then i thought it would have to do the same thing i do so maybe it wouldn't help. when i finally got a chance to check the API, it turns out there is a contains() method. it works about 8 times as fast now
less code too
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7779
    
  21

Randall Twede wrote:less code too

Maybe, but any time I see 8 "end-block"s in a row, I get brain-ache.

My advice:
1. Put this into a separate method.
2. See if you can't reduce some of those loops and/or if's. I can't remember the last time I wrote code nested 8 deep - or even if I ever have.

Also: Please DontWriteLongLines. It makes your thread very difficult to read. I'd correct them myself, but you have tons of them.
Remember: 80 characters max.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

putting it in a seperate method would probably be a good idea. the entire mouseReleased() method is pretty long.
as for the nesting, that is just the way this problem gets solved.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7779
    
  21

Randall Twede wrote:as for the nesting, that is just the way this problem gets solved.

No it isn't - or at least, it's certainly not the only way to solve it.

For starters, if you have two 'if' statements in a row, you can join them with an '&&'.

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a need for speed