[220683] Lower startup time with bug 208881
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/TaglibController.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/TaglibController.java
index e33b3ec..6f563e1 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/TaglibController.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/TaglibController.java
@@ -19,9 +19,11 @@
 
 import org.eclipse.core.filebuffers.FileBuffers;
 import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
+import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
 import org.eclipse.core.filebuffers.IFileBuffer;
 import org.eclipse.core.filebuffers.IFileBufferListener;
 import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.LocationKind;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.text.IDocument;
@@ -47,11 +49,13 @@
  * 
  * TODO: Remove the reparse penalty.
  */
-public class TaglibController implements IDocumentSetupParticipant {
+public class TaglibController implements IDocumentSetupParticipant, IDocumentSetupParticipantExtension {
 
 	class DocumentInfo implements ITaglibIndexListener {
 		IStructuredDocument document;
 		ITextFileBuffer textFileBuffer;
+		IPath location;
+		LocationKind locationKind;
 		TLDCMDocumentManager tldDocumentManager;
 
 		public void indexChanged(ITaglibIndexDelta delta) {
@@ -115,17 +119,30 @@
 						return;
 				}
 				Assert.isTrue(document instanceof IStructuredDocument, getClass().getName() + " SetupParticipant was called for non-IStructuredDocument"); //$NON-NLS-1$
-				DocumentInfo info = new DocumentInfo();
-				info.document = (IStructuredDocument) document;
-				info.textFileBuffer = (ITextFileBuffer) buffer;
-				info.tldDocumentManager = new TLDCMDocumentManager();
-				info.tldDocumentManager.setSourceParser((JSPSourceParser) info.document.getParser());
+
+				DocumentInfo info = null;
 				synchronized (_instance.fDocumentMap) {
-					_instance.fDocumentMap.put(document, info);
+					info = (DocumentInfo) _instance.fDocumentMap.get(document);
 				}
-				TaglibIndex.addTaglibIndexListener(info);
-				if (document instanceof BasicStructuredDocument) {
-					((BasicStructuredDocument) document).reparse(this);
+				if (info != null) {
+					// remember the buffer now
+					info.textFileBuffer = (ITextFileBuffer) buffer;
+				}
+				else {
+					info = new DocumentInfo();
+					info.document = (IStructuredDocument) document;
+					info.textFileBuffer = (ITextFileBuffer) buffer;
+					info.location = buffer.getLocation();
+					info.locationKind = LocationKind.NORMALIZE;
+					info.tldDocumentManager = new TLDCMDocumentManager();
+					info.tldDocumentManager.setSourceParser((JSPSourceParser) info.document.getParser());
+					synchronized (_instance.fDocumentMap) {
+						_instance.fDocumentMap.put(document, info);
+					}
+					TaglibIndex.addTaglibIndexListener(info);
+					if (document instanceof BasicStructuredDocument && document.getLength() > 0) {
+						((BasicStructuredDocument) document).reparse(this);
+					}
 				}
 			}
 		}
@@ -145,11 +162,11 @@
 			}
 			DocumentInfo info = null;
 			synchronized (fDocumentMap) {
-				Object[] keys = fDocumentMap.keySet().toArray();
-				for (int i = 0; i < keys.length; i++) {
-					info = (DocumentInfo) fDocumentMap.get(keys[i]);
+				Map.Entry[] entries = (Map.Entry[]) fDocumentMap.entrySet().toArray(new Map.Entry[fDocumentMap.size()]);
+				for (int i = 0; i < entries.length; i++) {
+					info = (DocumentInfo) entries[i].getValue();
 					if (info != null && info.textFileBuffer.equals(buffer)) {
-						fDocumentMap.remove(keys[i]);
+						fDocumentMap.remove(entries[i].getKey());
 						break;
 					}
 				}
@@ -217,11 +234,11 @@
 	static TaglibController _instance = null;
 	static private boolean fIsShutdown = false;
 
-	public static ITextFileBuffer getFileBuffer(IDocument document) {
+	public static IPath getLocation(IDocument document) {
 		synchronized (_instance.fDocumentMap) {
 			DocumentInfo info = (DocumentInfo) _instance.fDocumentMap.get(document);
 			if (info != null)
-				return info.textFileBuffer;
+				return info.location;
 			return null;
 		}
 	}
@@ -230,25 +247,25 @@
 	 * @param manager
 	 * @return
 	 */
-	public static ITextFileBuffer getFileBuffer(TLDCMDocumentManager manager) {
+	public static IPath getLocation(TLDCMDocumentManager manager) {
 		// if _instance is null, we are already shutting donw
 		if (_instance == null)
 			return null;
 
-		ITextFileBuffer buffer = null;
+		IPath location = null;
 		synchronized (_instance.fDocumentMap) {
 			Iterator docInfos = _instance.fDocumentMap.values().iterator();
-			while (docInfos.hasNext() && buffer == null) {
+			while (docInfos.hasNext() && location == null) {
 				DocumentInfo info = (DocumentInfo) docInfos.next();
 				if (info.tldDocumentManager.equals(manager))
-					buffer = info.textFileBuffer;
+					location = info.location;
 			}
 		}
-		return buffer;
+		return location;
 	}
 
 	public static TLDCMDocumentManager getTLDCMDocumentManager(IDocument document) {
-		// if _instance is null, we are already shutting donw
+		// if _instance is null, we are already shutting down
 		if (_instance == null)
 			return null;
 		synchronized (_instance.fDocumentMap) {
@@ -315,4 +332,36 @@
 			_instance.fJSPdocuments.add(document);
 		}
 	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension#setup(org.eclipse.jface.text.IDocument,
+	 *      org.eclipse.core.runtime.IPath,
+	 *      org.eclipse.core.filebuffers.LocationKind)
+	 */
+	public void setup(IDocument document, IPath location, LocationKind locationKind) {
+		// if we've already shutdown, just ignore
+		if (isShutdown())
+			return;
+		// reference the shared instance's documents directly
+		synchronized (_instance.fJSPdocuments) {
+			_instance.fJSPdocuments.add(document);
+		}
+
+		DocumentInfo info = new DocumentInfo();
+		info.document = (IStructuredDocument) document;
+		info.textFileBuffer = null; // will be supplied later
+		info.location = location;
+		info.locationKind = locationKind;
+		info.tldDocumentManager = new TLDCMDocumentManager();
+		synchronized (_instance.fDocumentMap) {
+			_instance.fDocumentMap.put(document, info);
+		}
+		info.tldDocumentManager.setSourceParser((JSPSourceParser) info.document.getParser());
+		if (document instanceof BasicStructuredDocument && document.getLength() > 0) {
+			((BasicStructuredDocument) document).reparse(this);
+		}
+		TaglibIndex.addTaglibIndexListener(info);
+	}
 }
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/TLDCMDocumentManager.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/TLDCMDocumentManager.java
index 8890620..7ee622d 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/TLDCMDocumentManager.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/TLDCMDocumentManager.java
@@ -227,12 +227,12 @@
 				includedFile = StringUtils.strip(includedFile).trim();
 				IPath filePath = null;
 				if (getIncludes().isEmpty())
-					filePath = FacetModuleCoreSupport.resolve(TaglibController.getFileBuffer(TLDCMDocumentManager.this).getLocation(), includedFile);
+					filePath = FacetModuleCoreSupport.resolve(TaglibController.getLocation(TLDCMDocumentManager.this), includedFile);
 				else
 					filePath = FacetModuleCoreSupport.resolve((IPath) getIncludes().peek(), includedFile);
 
 				// check for "loops"
-				if (filePath != null && !getIncludes().contains(filePath) && !filePath.equals(TaglibController.getFileBuffer(TLDCMDocumentManager.this).getLocation())) {
+				if (filePath != null && !getIncludes().contains(filePath) && !filePath.equals(TaglibController.getLocation(TLDCMDocumentManager.this))) {
 					/*
 					 * Prevent slow performance when editing scriptlet part of
 					 * the JSP by only processing includes if they've been
@@ -869,7 +869,7 @@
 			path = (IPath) getIncludes().peek();
 		}
 		else {
-			path = TaglibController.getFileBuffer(this).getLocation();
+			path = TaglibController.getLocation(this);
 		}
 
 		return path;