You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/11/20 22:37:47 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util MimeHeaders.java
costin 00/11/20 13:37:47
Modified: src/share/org/apache/tomcat/util MimeHeaders.java
Log:
Added a new method to MimeHeaders to do fast ( indexed ) searches
for multi-value headers.
The whole MimeHeaders will be re-written soon ( I have a first draft,
but I want to make sure the base class will be usable for Parameters
and Cookies too )
Revision Changes Path
1.17 +37 -0 jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaders.java
Index: MimeHeaders.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaders.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- MimeHeaders.java 2000/11/01 21:43:28 1.16
+++ MimeHeaders.java 2000/11/20 21:37:45 1.17
@@ -89,6 +89,25 @@
* of string values).
*/
+/* Headers are first parsed and stored in the order they are
+ received. This is based on the fact that most servlets will not
+ directly access all headers, and most headers are single-valued.
+ ( the alternative - a hash or similar data structure - will add
+ an overhead that is not needed in most cases )
+
+ Apache seems to be using a similar method for storing and manipulating
+ headers.
+
+ Future enhancements:
+ - hash the headers the first time a header is requested ( i.e. if the
+ servlet needs direct access to headers).
+ - scan "common" values ( length, cookies, etc ) during the parse
+ ( addHeader hook )
+
+*/
+
+
+
/**
* Memory-efficient repository for Mime Headers. When the object is recycled, it
* will keep the allocated headers[] and all the MimeHeaderField - no GC is generated.
@@ -170,6 +189,24 @@
return n >= 0 && n < count ? headers[n].getValue() : null;
}
+ /** Find the index of a header with the given name.
+ */
+ public int findHeader( String name, int starting ) {
+ // We can use a hash - but it's not clear how much
+ // benefit you can get - there is an overhead
+ // and the number of headers is small (4-5 ?)
+ // Another problem is that we'll pay the overhead
+ // of constructing the hashtable
+
+ // A custom search tree may be better
+ for (int i = starting; i < count; i++) {
+ if (headers[i].getName().equalsIgnoreCase(name)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
// -------------------- --------------------
/**