Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4409367

Fix slow non-OO code in java.awt.Component.update()

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta
    • generic
    • generic



      Name: boT120536 Date: 01/29/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed
      mode)

      Recently I've had a look into the sources and got quite a shock.
      The update() method of java.awt.Component contains an ugly piece of code:

      ==== CODE ====
          public void update(Graphics g) {
              if ((this instanceof java.awt.Canvas) ||
                  (this instanceof java.awt.Panel) ||
                  (this instanceof java.awt.Frame) ||
                  (this instanceof java.awt.Dialog) ||
                  (this instanceof java.awt.Window)) {

                  g.clearRect(0, 0, width, height);
              }
              paint(g);
          }
      ==== EOC ====

      This looks like a quick hack which moved in during introduction of lightweight
      components.

      The use of instanceof is not only against all OO principles, it also slows down
      execution of all extending classes which do not overwrite update() completely.
      Furthermore the test for Frame and Dialog are unnecessary because they are
      included in the Window test.
      Please move the clearRect code to the classes where it belongs, i.e. Canvas,
      Panel and Window.
      (Review ID: 115927)
      ======================================================================

            ehawkessunw Eric Hawkes (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: