Patch: trivial optimizations
Anthony Green
green@cygnus.com
Sat Apr 8 16:45:00 GMT 2000
Here are four simple optimizations I discovered by profiling
MakeMimeType.
_Jv_MonitorEnter is called quite often. The _Jv_MonitorEnter change
eliminates a useless check.
The `elements' functions in array.h should have been marked as inline
from the very start.
The Vector and StringTokenizer changes are essentially manual inlines.
As horrible as this sounds, I think the changes are relatively easy to
swallow.
2000-04-08 Anthony Green <green@redhat.com>
* java/lang/natObject.cc (_Jv_MonitorEnter): Only perform null
check when we have to.
* gcj/array.h: Mark elements(JArray<T>& x) and elements(JArray<T>*
x) as `inline'.
* java/util/StringTokenizer.java: Minor optimization. Eliminates
one method call.
* java/util/Vector.java (VectorEnumeration.nextElement): Manually
inline hasMoreElements.
Index: libjava/java/lang/natObject.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natObject.cc,v
retrieving revision 1.9
diff -c -u -p -r1.9 natObject.cc
--- natObject.cc 2000/03/28 02:22:24 1.9
+++ natObject.cc 2000/04/08 23:32:00
@@ -18,6 +18,7 @@ details. */
#include <jvm.h>
#include <java/lang/Object.h>
#include <java-threads.h>
+#include <java-signal.h>
#include <java/lang/CloneNotSupportedException.h>
#include <java/lang/IllegalArgumentException.h>
#include <java/lang/IllegalMonitorStateException.h>
@@ -224,8 +225,10 @@ _Jv_InitializeSyncMutex (void)
jint
_Jv_MonitorEnter (jobject obj)
{
+#ifndef HANDLE_SEGV
if (! obj)
JvThrow (new java::lang::NullPointerException);
+#endif
if (INIT_NEEDED (obj))
obj->sync_init ();
_Jv_SyncInfo *si = (_Jv_SyncInfo *) obj->sync_info;
Index: libjava/gcj/array.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/gcj/array.h,v
retrieving revision 1.7
diff -c -u -p -r1.7 array.h
--- array.h 2000/03/07 19:55:24 1.7
+++ array.h 2000/04/08 23:32:00
@@ -36,9 +36,9 @@ public:
};
template<class T>
-T* elements(JArray<T>& x) { return x.data; }
+inline T* elements(JArray<T>& x) { return x.data; }
template<class T>
-T* elements(JArray<T>* x) { return x->data; }
+inline T* elements(JArray<T>* x) { return x->data; }
}; // end extern "Java"
Index: libjava/java/util/StringTokenizer.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/StringTokenizer.java,v
retrieving revision 1.3
diff -c -u -p -r1.3 StringTokenizer.java
--- StringTokenizer.java 2000/03/07 19:55:27 1.3
+++ StringTokenizer.java 2000/04/08 23:32:00
@@ -180,6 +180,6 @@ public class StringTokenizer implements
// more readable this way, so we'll take the hit on efficiency.
private boolean isDelimiter(char ch)
{
- return delimiters.indexOf(ch) >= 0;
+ return delimiters.indexOf(ch, 0) >= 0;
}
}
Index: libjava/java/util/Vector.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/Vector.java,v
retrieving revision 1.3
diff -c -u -p -r1.3 Vector.java
--- Vector.java 2000/03/07 19:55:27 1.3
+++ Vector.java 2000/04/08 23:32:01
@@ -38,7 +38,7 @@ class VectorEnumeration implements Enume
public Object nextElement()
{
- if (!hasMoreElements())
+ if (! (enumIndex < enumVec.size()))
throw new NoSuchElementException();
return enumVec.elementData[enumIndex++];
--
Anthony Green Red Hat
Sunnyvale, California
More information about the Java-patches
mailing list