[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

mjs mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:09:45 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit d64a9dd3e232830aff4223448062c98d212b6c71
Author: mjs <mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Nov 6 17:12:28 2003 +0000

            Reviewed by Darin.
    
    	- fixed 3475366 - 4.5% of time spent making html event listeners on slow intel page.
    
    	6% speedup on intel page, 1% speedup on cvs-base PLT.
    
            * khtml/ecma/kjs_events.cpp:
            (JSEventListener::JSEventListener): Don't add self to hashtable if imp is null (which
    	can now happen in the lazy listener case).
            (JSEventListener::~JSEventListener): Ditto on removing.
            (JSEventListener::listenerObj): Made this virtual.
            (JSLazyEventListener::JSLazyEventListener): New constructor.
    	(JSLazyEventListener::handleEvent): call parseCode, then
    	superclass if it appeared to succeed.
            (JSLazyEventListener::listenerObj): call parseCode, then superclass.
            (JSLazyEventListener::parseCode):
            (KJS::getNodeEventListener): Check for null listenerObjImp in case of
    	lazy listener that failed to parse.
            * khtml/ecma/kjs_dom.cpp:
    	(DOMNode::getListener): Ditto.
            * khtml/ecma/kjs_html.cpp:
            (Image::getValueProperty): Ditto.
            * khtml/ecma/kjs_events.h:
    	(KJS::JSEventListener::listenerObjImp): call listenerObj() virtual
    	method and get imp from the result.
            * khtml/ecma/kjs_proxy.cpp:
            (KJSProxyImpl::createHTMLEventHandler): Don't parse the code here, make a lazy
    	listener.
            * khtml/ecma/kjs_window.cpp:
            (Window::getJSLazyEventListener): make a new JSLazyEventListener - no need
    	to check the listeners hashtable cause a brand new lazy listener won't have
    	a function anyway.
            * khtml/ecma/kjs_window.h: Prototype new method.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5404 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 17234f5..6b48170 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -2,6 +2,42 @@
 
         Reviewed by Darin.
 
+	- fixed 3475366 - 4.5% of time spent making html event listeners on slow intel page.
+
+	6% speedup on intel page, 1% speedup on cvs-base PLT.
+	
+        * khtml/ecma/kjs_events.cpp:
+        (JSEventListener::JSEventListener): Don't add self to hashtable if imp is null (which
+	can now happen in the lazy listener case).
+        (JSEventListener::~JSEventListener): Ditto on removing.
+        (JSEventListener::listenerObj): Made this virtual.
+        (JSLazyEventListener::JSLazyEventListener): New constructor.
+	(JSLazyEventListener::handleEvent): call parseCode, then
+	superclass if it appeared to succeed.
+        (JSLazyEventListener::listenerObj): call parseCode, then superclass.
+        (JSLazyEventListener::parseCode):
+        (KJS::getNodeEventListener): Check for null listenerObjImp in case of
+	lazy listener that failed to parse.
+        * khtml/ecma/kjs_dom.cpp:
+	(DOMNode::getListener): Ditto.
+        * khtml/ecma/kjs_html.cpp:
+        (Image::getValueProperty): Ditto.
+        * khtml/ecma/kjs_events.h:
+	(KJS::JSEventListener::listenerObjImp): call listenerObj() virtual
+	method and get imp from the result.
+        * khtml/ecma/kjs_proxy.cpp:
+        (KJSProxyImpl::createHTMLEventHandler): Don't parse the code here, make a lazy
+	listener.
+        * khtml/ecma/kjs_window.cpp:
+        (Window::getJSLazyEventListener): make a new JSLazyEventListener - no need
+	to check the listeners hashtable cause a brand new lazy listener won't have
+	a function anyway.
+        * khtml/ecma/kjs_window.h: Prototype new method.
+
+2003-11-06  Maciej Stachowiak  <mjs at apple.com>
+
+        Reviewed by Darin.
+
 	- fixed 3475397 - REGRESSION: relative URLs on page load test sometimes contain garbage, leading to missing images
 	
         * kwq/KWQKURL.mm:
diff --git a/WebCore/khtml/ecma/kjs_dom.cpp b/WebCore/khtml/ecma/kjs_dom.cpp
index 278d96a..74db715 100644
--- a/WebCore/khtml/ecma/kjs_dom.cpp
+++ b/WebCore/khtml/ecma/kjs_dom.cpp
@@ -415,8 +415,9 @@ void DOMNode::setListener(ExecState *exec, int eventId, Value func) const
 Value DOMNode::getListener(int eventId) const
 {
     DOM::EventListener *listener = node.handle()->getHTMLEventListener(eventId);
-    if (listener)
-	return static_cast<JSEventListener*>(listener)->listenerObj();
+    JSEventListener *jsListener = static_cast<JSEventListener*>(listener);
+    if ( jsListener && jsListener->listenerObjImp() )
+	return jsListener->listenerObj();
     else
 	return Null();
 }
diff --git a/WebCore/khtml/ecma/kjs_events.cpp b/WebCore/khtml/ecma/kjs_events.cpp
index 2bf7f7c..b523184 100644
--- a/WebCore/khtml/ecma/kjs_events.cpp
+++ b/WebCore/khtml/ecma/kjs_events.cpp
@@ -43,12 +43,16 @@ JSEventListener::JSEventListener(Object _listener, const Object &_win, bool _htm
     //fprintf(stderr,"JSEventListener::JSEventListener this=%p listener=%p\n",this,listener.imp());
     html = _html;
     win = _win;
-    static_cast<Window*>(win.imp())->jsEventListeners.insert(_listener.imp(), this);
+    if (_listener.imp()) {
+      static_cast<Window*>(win.imp())->jsEventListeners.insert(_listener.imp(), this);
+    }
 }
 
 JSEventListener::~JSEventListener()
 {
-    static_cast<Window*>(win.imp())->jsEventListeners.remove(listener.imp());
+    if (listener.imp()) {
+      static_cast<Window*>(win.imp())->jsEventListeners.remove(listener.imp());
+    }
     //fprintf(stderr,"JSEventListener::~JSEventListener this=%p listener=%p\n",this,listener.imp());
 }
 
@@ -59,7 +63,7 @@ void JSEventListener::handleEvent(DOM::Event &evt, bool isWindowEvent)
     return;
 #endif
   KHTMLPart *part = static_cast<Window*>(win.imp())->part();
-  KJSProxy *proxy = 0L;
+  KJSProxy *proxy = 0;
   if (part)
       proxy = KJSProxy::proxy( part );
 
@@ -131,15 +135,88 @@ DOM::DOMString JSEventListener::eventListenerType()
 	return "_khtml_JSEventListener";
 }
 
+
+Object JSEventListener::listenerObj() const
+{ 
+  return listener; 
+}
+
+JSLazyEventListener::JSLazyEventListener(QString _code, const Object &_win, bool _html)
+  : JSEventListener(Object(), _win, _html),
+    code(_code),
+    parsed(false)
+{
+}
+
+void JSLazyEventListener::handleEvent(DOM::Event &evt, bool isWindowEvent)
+{
+  parseCode();
+  if (!listener.isNull()) {
+    JSEventListener::handleEvent(evt, isWindowEvent);
+  }
+}
+
+
+Object JSLazyEventListener::listenerObj() const
+{
+  parseCode();
+  return listener;
+}
+
+void JSLazyEventListener::parseCode() const
+{
+  if (!parsed) {
+    KHTMLPart *part = static_cast<Window*>(win.imp())->part();
+    KJSProxy *proxy = 0L;
+    if (part)
+      proxy = KJSProxy::proxy( part );
+
+    if (proxy) {
+      KJS::ScriptInterpreter *interpreter = static_cast<KJS::ScriptInterpreter *>(proxy->interpreter());
+      ExecState *exec = interpreter->globalExec();
+
+      //KJS::Constructor constr(KJS::Global::current().get("Function").imp());
+      KJS::Object constr = interpreter->builtinFunction();
+      KJS::List args;
+
+      static KJS::String eventString("event");
+
+      args.append(eventString);
+      args.append(KJS::String(code));
+      listener = constr.construct(exec, args); // ### is globalExec ok ?
+      
+      if ( exec->hadException() ) {
+	exec->clearException();
+
+	// failed to parse, so let's just make this listener a no-op
+	listener = Object();
+      }
+    }
+
+    // no more need to keep the unparsed code around
+    code = QString();
+    
+    if (!listener.isNull()) {
+      static_cast<Window*>(win.imp())->jsEventListeners.insert(listener.imp(), 
+							       (KJS::JSEventListener *)(this));
+    }
+    
+    parsed = true;
+  }
+}
+
 Value KJS::getNodeEventListener(DOM::Node n, int eventId)
 {
     DOM::EventListener *listener = n.handle()->getHTMLEventListener(eventId);
-    if (listener)
-	return static_cast<JSEventListener*>(listener)->listenerObj();
+    JSEventListener *jsListener = static_cast<JSEventListener*>(listener);
+    if ( jsListener && jsListener->listenerObjImp() )
+	return jsListener->listenerObj();
     else
 	return Null();
 }
 
+
+
 // -------------------------------------------------------------------------
 
 const ClassInfo EventConstructor::info = { "EventConstructor", 0, &EventConstructorTable, 0 };
diff --git a/WebCore/khtml/ecma/kjs_events.h b/WebCore/khtml/ecma/kjs_events.h
index 3d59868..1f4a24c 100644
--- a/WebCore/khtml/ecma/kjs_events.h
+++ b/WebCore/khtml/ecma/kjs_events.h
@@ -36,14 +36,27 @@ namespace KJS {
     virtual ~JSEventListener();
     virtual void handleEvent(DOM::Event &evt, bool isWindowEvent);
     virtual DOM::DOMString eventListenerType();
-    Object listenerObj() const { return listener; }
-    ObjectImp *listenerObjImp() const { return listener.imp(); }
+    virtual Object listenerObj() const;
+    ObjectImp *listenerObjImp() const { return listenerObj().imp(); }
   protected:
-    Object listener;
+    mutable Object listener;
     bool html;
     Object win;
   };
 
+  class JSLazyEventListener : public JSEventListener {
+  public:
+    JSLazyEventListener(QString _code, const Object &_win, bool _html = false);
+    virtual void handleEvent(DOM::Event &evt, bool isWindowEvent);
+    Object listenerObj() const;
+  private:
+    void parseCode() const;
+    
+    mutable QString code;
+    mutable bool parsed;
+  };
+
+
   Value getNodeEventListener(DOM::Node n, int eventId);
 
   // Constructor for Event - currently only used for some global vars
diff --git a/WebCore/khtml/ecma/kjs_html.cpp b/WebCore/khtml/ecma/kjs_html.cpp
index 604d1d6..bc30238 100644
--- a/WebCore/khtml/ecma/kjs_html.cpp
+++ b/WebCore/khtml/ecma/kjs_html.cpp
@@ -3185,7 +3185,7 @@ Value Image::getValueProperty(ExecState *, int token) const
   case Complete:
     return Boolean(!img || img->status() >= khtml::CachedObject::Persistent);
   case OnLoad:
-    if (onLoadListener) {
+    if (onLoadListener && onLoadListener->listenerObjImp()) {
       return onLoadListener->listenerObj();
     } else {
       return Null();
diff --git a/WebCore/khtml/ecma/kjs_proxy.cpp b/WebCore/khtml/ecma/kjs_proxy.cpp
index 5ac049f..e6bb265 100644
--- a/WebCore/khtml/ecma/kjs_proxy.cpp
+++ b/WebCore/khtml/ecma/kjs_proxy.cpp
@@ -164,14 +164,8 @@ DOM::EventListener *KJSProxyImpl::createHTMLEventHandler(QString sourceUrl, QStr
 #endif
 
   initScript();
-  //KJS::Constructor constr(KJS::Global::current().get("Function").imp());
-  KJS::Object constr = m_script->builtinFunction();
-  KJS::List args;
-  args.append(KJS::String("event"));
-  args.append(KJS::String(code));
-  Object handlerFunc = constr.construct(m_script->globalExec(), args); // ### is globalExec ok ?
-
-  return KJS::Window::retrieveWindow(m_part)->getJSEventListener(handlerFunc,true);
+
+  return KJS::Window::retrieveWindow(m_part)->getJSLazyEventListener(code,true);
 }
 
 void KJSProxyImpl::finishedWithEvent(const DOM::Event &event)
diff --git a/WebCore/khtml/ecma/kjs_window.cpp b/WebCore/khtml/ecma/kjs_window.cpp
index 9ea270e..2cfeffd 100644
--- a/WebCore/khtml/ecma/kjs_window.cpp
+++ b/WebCore/khtml/ecma/kjs_window.cpp
@@ -1032,6 +1032,11 @@ JSEventListener *Window::getJSEventListener(const Value& val, bool html)
   return new JSEventListener(Object(listenerObject), Object(this), html);
 }
 
+JSLazyEventListener *Window::getJSLazyEventListener(const QString& code, bool html)
+{
+  return new JSLazyEventListener(code, Object(this), html);
+}
+
 void Window::clear( ExecState *exec )
 {
   KJS::Interpreter::lock();
diff --git a/WebCore/khtml/ecma/kjs_window.h b/WebCore/khtml/ecma/kjs_window.h
index 110fdea..da0ace5 100644
--- a/WebCore/khtml/ecma/kjs_window.h
+++ b/WebCore/khtml/ecma/kjs_window.h
@@ -41,6 +41,7 @@ namespace KJS {
   class History;
   class FrameArray;
   class JSEventListener;
+  class JSLazyEventListener;
 
   class Screen : public ObjectImp {
   public:
@@ -100,6 +101,7 @@ namespace KJS {
     bool isSafeScript(ExecState *exec) const;
     Location *location() const;
     JSEventListener *getJSEventListener(const Value &val, bool html = false);
+    JSLazyEventListener *getJSLazyEventListener(const QString &code, bool html = false);
     void clear( ExecState *exec );
     virtual UString toString(ExecState *exec) const;
 
diff --git a/WebCore/khtml/xml/dom_docimpl.cpp b/WebCore/khtml/xml/dom_docimpl.cpp
index 528081c..9a4086b 100644
--- a/WebCore/khtml/xml/dom_docimpl.cpp
+++ b/WebCore/khtml/xml/dom_docimpl.cpp
@@ -2396,7 +2396,7 @@ void DocumentImpl::setDecoder(Decoder *decoder)
 
 QString DocumentImpl::completeURL(const QString &URL)
 {
-    return KURL(baseURL(), URL, m_decoder ? m_decoder->codec() : 0).url();
+*    return KURL(baseURL(), URL, m_decoder ? m_decoder->codec() : 0).url();
 }
 
 bool DocumentImpl::inPageCache()

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list