Reviewers: Lex,

Message:
Here's an example of what the new loader output looks like:

package com.google.gwt.lang.asyncloaders;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.core.client.impl.AsyncFragmentLoader;

public class AsyncLoader1 {
  // Callbacks that are pending
  private static AsyncLoader1__Callback callbacksHead = null;
  // The tail of the callbacks list
  private static AsyncLoader1__Callback callbacksTail = null;
  // A callback caller for this entry point
  private static AsyncLoader1 instance = null;

  public static void onLoad() {
    instance = new AsyncLoader1();
    AsyncFragmentLoader.BROWSER_LOADER.fragmentHasLoaded(1);
    AsyncFragmentLoader.BROWSER_LOADER.logEventProgress("runCallbacks1",
"begin");
    instance.runCallbacks();
    AsyncFragmentLoader.BROWSER_LOADER.logEventProgress("runCallbacks1",
"end");
  }

  public static void runAsync(RunAsyncCallback callback) {
    AsyncLoader1__Callback newCallback = new AsyncLoader1__Callback();
    newCallback.callback = callback;
    if (callbacksTail != null) {
      callbacksTail.next = newCallback;
    }
    callbacksTail = newCallback;
    if (callbacksHead == null) {
      callbacksHead = newCallback;
    }
    if (instance != null) {
      instance.runCallbacks();
      return;
    }
    if (!AsyncFragmentLoader.BROWSER_LOADER.isLoading(1)) {
      AsyncFragmentLoader.BROWSER_LOADER.inject(1,
          new AsyncFragmentLoader.LoadErrorHandler() {
            public void loadFailed(Throwable reason) {
              runCallbackOnFailures(reason);
            }
          });
    }
  }

  private static void runCallbackOnFailures(Throwable e) {
    while (callbacksHead != null) {
      callbacksHead.callback.onFailure(e);
      callbacksHead = callbacksHead.next;
    }
    callbacksTail = null;
  }

  public void runCallbacks() {
    while (callbacksHead != null) {
      GWT.UncaughtExceptionHandler handler =
GWT.getUncaughtExceptionHandler();
      AsyncLoader1__Callback next = callbacksHead;
      callbacksHead = callbacksHead.next;
      if (callbacksHead == null) {
        callbacksTail = null;
      }
      if (handler == null) {
        next.callback.onSuccess();
      } else {
        try {
          next.callback.onSuccess();
        } catch (Throwable e) {
          handler.onUncaughtException(e);
        }
      }
    }
  }
}



http://gwt-code-reviews.appspot.com/159811/diff/1/2
File dev/core/src/com/google/gwt/dev/jjs/impl/FragmentLoaderCreator.java
(left):

http://gwt-code-reviews.appspot.com/159811/diff/1/2#oldcode114
Line 114: private void generateOnErrorMethod(PrintWriter srcWriter) {
I pulled this method because I couldn't see any callers.  Was this still
needed?

http://gwt-code-reviews.appspot.com/159811/diff/1/4
File user/src/com/google/gwt/core/client/prefetch/Prefetcher.java
(right):

http://gwt-code-reviews.appspot.com/159811/diff/1/4#newcode33
Line 33: public static void prefetch(Collection<? extends
PrefetchableResource> resources) {
Wasn't sure about this change, but I thought I'd suggest it.
Technically, since the code below the "GWT.isScript()" is JS only (where
there's no range checking), we don't have to know the correct size up
front.

Description:
A few runAsync-related code size improvements.

1) Removes the clinit, AsyncLoader__Supers, and loading fields from
generated AsyncLoaders.  PRETTY mode Showcase's initial fragment drops
from 500k to 480k.  Probably less impressive in OBF.  A tiny improvement
within the split fragments, too.

2) Removes the last couple uses of JRE collections from
AsyncFragmentLoader in favor of arrays.

3) Removes a missed logEventProgress Integer -> int conversion that was
begun in an earlier commit.


Please review this at http://gwt-code-reviews.appspot.com/159811

Affected files:
  M dev/core/src/com/google/gwt/dev/jjs/impl/FragmentLoaderCreator.java
  M user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
  M user/src/com/google/gwt/core/client/prefetch/Prefetcher.java


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to