This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: More efficient ResourceBundle calls


This patch changes various ResourceBundle.getBundle() calls to use the 3-argument form which includes a ClassLoader parameter. This call is more efficient because it means getBundle() does not have to walk the stack to find the calling classloader. This should speed up some Date/Calendar operations which are currently quite slow due to repeated calling classloader checks and that people have complained about in the past.

We will of course in future improve the stack trace code so that the calling-classloader check is more efficient, however it will always be more efficient to pass the ClassLoader explicitly.

I'm checking this in.

Regards

Bryce

2004-05-28  Bryce McKinlay  <mckinlay@redhat.com>

	* java/util/Calendar.java: Change ResourceBundle.getBundle() calls
	to pass ClassLoader argument.
	* java/util/GregorianCalendar.java: Likewise.
	* java/util/Currency.java: Likewise.
	* java/text/BreakIterator.java: Likewise.
	* java/text/Collator.java: Likewise.
	* java/text/DateFormat.java: Likewise.
	* java/text/DateFormatSymbols.java: Likewise.
	* java/text/DecimalFormatSymbols.java: Likewise.
	* java/text/NumberFormat.java: Likewise.
	* java/awt/Window.java: Likewise.

Index: java/util/Calendar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/Calendar.java,v
retrieving revision 1.19
diff -u -r1.19 Calendar.java
--- java/util/Calendar.java	7 May 2004 04:18:19 -0000	1.19
+++ java/util/Calendar.java	29 May 2004 00:01:30 -0000
@@ -376,7 +376,8 @@
    */
   private static ResourceBundle getBundle(Locale locale) 
   {
-    return ResourceBundle.getBundle(bundleName, locale);
+    return ResourceBundle.getBundle(bundleName, locale,
+      Calendar.class.getClassLoader());
   }
 
   /**
Index: java/util/GregorianCalendar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/GregorianCalendar.java,v
retrieving revision 1.19
diff -u -r1.19 GregorianCalendar.java
--- java/util/GregorianCalendar.java	30 Dec 2003 19:56:49 -0000	1.19
+++ java/util/GregorianCalendar.java	29 May 2004 00:01:30 -0000
@@ -89,7 +89,8 @@
    */
   private static ResourceBundle getBundle(Locale locale) 
   {
-    return ResourceBundle.getBundle(bundleName, locale);
+    return ResourceBundle.getBundle(bundleName, locale,
+      GregorianCalendar.class.getClassLoader());
   }
 
   /**
Index: java/util/Currency.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/Currency.java,v
retrieving revision 1.2
diff -u -r1.2 Currency.java
--- java/util/Currency.java	23 Apr 2004 06:36:04 -0000	1.2
+++ java/util/Currency.java	29 May 2004 00:01:30 -0000
@@ -54,7 +54,8 @@
   private Currency (Locale loc)
   {
     this.locale = loc;
-    this.res = ResourceBundle.getBundle ("gnu.java.locale.LocaleInformation", locale);
+    this.res = ResourceBundle.getBundle ("gnu.java.locale.LocaleInformation", 
+      locale, Currency.class.getClassLoader());
   }
 
   /**
@@ -148,7 +149,9 @@
     // First we need to implement fully LocaleInformation*.java
     try
       {
-	ResourceBundle res = ResourceBundle.getBundle ("gnu.java.locale.LocaleInformation", locale);
+	ResourceBundle res = 
+	  ResourceBundle.getBundle ("gnu.java.locale.LocaleInformation", 
+				    locale, Currency.class.getClassLoader());
 
 	if (res.equals(this.res))
 	  return res.getString ("currencySymbol");
Index: java/text/BreakIterator.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/BreakIterator.java,v
retrieving revision 1.7
diff -u -r1.7 BreakIterator.java
--- java/text/BreakIterator.java	30 Apr 2003 13:22:45 -0000	1.7
+++ java/text/BreakIterator.java	29 May 2004 00:01:30 -0000
@@ -136,7 +136,7 @@
       {
 	ResourceBundle res
 	  = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
-				     loc);
+				     loc, BreakIterator.class.getClassLoader());
 	className = res.getString(type);
       }
     catch (MissingResourceException x)
Index: java/text/Collator.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/Collator.java,v
retrieving revision 1.13
diff -u -r1.13 Collator.java
--- java/text/Collator.java	5 May 2004 07:35:49 -0000	1.13
+++ java/text/Collator.java	29 May 2004 00:01:30 -0000
@@ -303,7 +303,7 @@
     try
       {
 	res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
-				       loc);
+				       loc, Collator.class.getClassLoader());
 	pattern = res.getString("collation_rules");
       }
     catch (MissingResourceException x)
Index: java/text/DateFormat.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/DateFormat.java,v
retrieving revision 1.13
diff -u -r1.13 DateFormat.java
--- java/text/DateFormat.java	20 Apr 2004 14:45:02 -0000	1.13
+++ java/text/DateFormat.java	29 May 2004 00:01:30 -0000
@@ -325,7 +325,7 @@
     try
       {
 	res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
-				       loc);
+				       loc, DateFormat.class.getClassLoader());
       }
     catch (MissingResourceException x)
       {
Index: java/text/DateFormatSymbols.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/DateFormatSymbols.java,v
retrieving revision 1.15
diff -u -r1.15 DateFormatSymbols.java
--- java/text/DateFormatSymbols.java	20 Apr 2004 14:45:04 -0000	1.15
+++ java/text/DateFormatSymbols.java	29 May 2004 00:01:30 -0000
@@ -98,7 +98,8 @@
   public DateFormatSymbols (Locale locale) throws MissingResourceException
   {
     ResourceBundle res
-      = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale);
+      = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale,
+      				 getClass().getClassLoader());
 
     ampms = res.getStringArray ("ampms");
     eras = res.getStringArray ("eras");
Index: java/text/DecimalFormatSymbols.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/DecimalFormatSymbols.java,v
retrieving revision 1.13
diff -u -r1.13 DecimalFormatSymbols.java
--- java/text/DecimalFormatSymbols.java	5 May 2004 07:35:49 -0000	1.13
+++ java/text/DecimalFormatSymbols.java	29 May 2004 00:01:30 -0000
@@ -130,7 +130,7 @@
     try
       {
 	res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
-				       loc);
+		loc, DecimalFormatSymbols.class.getClassLoader());
       }
     catch (MissingResourceException x)
       {
Index: java/text/NumberFormat.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/NumberFormat.java,v
retrieving revision 1.13
diff -u -r1.13 NumberFormat.java
--- java/text/NumberFormat.java	5 May 2004 07:35:49 -0000	1.13
+++ java/text/NumberFormat.java	29 May 2004 00:01:30 -0000
@@ -310,7 +310,7 @@
     try
       {
 	res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
-				       loc);
+		loc, NumberFormat.class.getClassLoader());
       }
     catch (MissingResourceException x)
       {
Index: java/awt/Window.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Window.java,v
retrieving revision 1.34
diff -u -r1.34 Window.java
--- java/awt/Window.java	27 May 2004 06:17:37 -0000	1.34
+++ java/awt/Window.java	29 May 2004 00:01:30 -0000
@@ -703,7 +703,8 @@
    */
   public void applyResourceBundle(String rbName)
   {
-    ResourceBundle rb = ResourceBundle.getBundle(rbName);
+    ResourceBundle rb = ResourceBundle.getBundle(rbName, Locale.getDefault(),
+      Window.class.getClassLoader());
     if (rb != null)
       applyResourceBundle(rb);    
   }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]