• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a need for speed

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic