Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 311129

Summary: [Browser][Mozilla]Code refactoring of Parse method in nsID class
Product: [Eclipse Project] Platform Reporter: pei na <peina>
Component: SWTAssignee: Grant Gayed <grant_gayed>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: carolynmacleod4
Version: 3.6Flags: carolynmacleod4: review+
Target Milestone: 3.6 RC1   
Hardware: PC   
OS: All   
Whiteboard:
Attachments:
Description Flags
final patch based on Car's feedback none

Description pei na CLA 2010-04-29 23:37:39 EDT
Build Identifier: I20080617-2000

The Parse method will create 36 new String objects for each new nsID object.  So there will be thousands of temp String objects during the creation of a single browser instance.

public nsID(String id) {
	Parse(id);
}


public void Parse (String aIDStr) {
	if (aIDStr == null) throw new Error ();
	int i = 0;
	for (; i < 8; i++) m0 = (m0 << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16);
	if (aIDStr.charAt (i++) != '-') throw new Error ();
	for (; i < 13; i++) m1 = (short)((m1 << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
	if (aIDStr.charAt (i++) != '-') throw new Error ();
	for (; i < 18; i++) m2 = (short)((m2 << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
	if (aIDStr.charAt (i++) != '-') throw new Error ();
	for (; i < 21; i++) m3[0] = (byte)((m3[0] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
	for (; i < 23; i++) m3[1] = (byte)((m3[1] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
	if (aIDStr.charAt (i++) != '-') throw new Error ();
	for (; i < 26; i++) m3[2] = (byte)((m3[2] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
	for (; i < 28; i++) m3[3] = (byte)((m3[3] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
	for (; i < 30; i++) m3[4] = (byte)((m3[4] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
	for (; i < 32; i++) m3[5] = (byte)((m3[5] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
	for (; i < 34; i++) m3[6] = (byte)((m3[6] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
	for (; i < 36; i++) m3[7] = (byte)((m3[7] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
}


Could we change it like this?

public void Parse(String aIDStr) {
	if(aIDStr == null) throw new Error ();
	int i = 0;
	Integer.parseInt (aIDStr.substring (i, i + 1), 16);
	for (; i < 8; i++) m0 = (m0 << 4) + Character.digit(aIDStr.charAt(i),16);
	if (aIDStr.charAt (i++) != '-') throw new Error ();
	for (; i < 13; i++) m1 = (short)((m1 << 4) + Character.digit(aIDStr.charAt(i),16));
	if (aIDStr.charAt (i++) != '-') throw new Error ();
	for (; i < 18; i++) m2 = (short)((m2 << 4) + Character.digit(aIDStr.charAt(i),16));
	if (aIDStr.charAt (i++) != '-') throw new Error ();
	for (; i < 21; i++) m3[0] = (byte)((m3[0] << 4) + Character.digit(aIDStr.charAt(i),16));
	for (; i < 23; i++) m3[1] = (byte)((m3[1] << 4) + Character.digit(aIDStr.charAt(i),16));
	if (aIDStr.charAt (i++) != '-') throw new Error ();
	for (; i < 26; i++) m3[2] = (byte)((m3[2] << 4) + Character.digit(aIDStr.charAt(i),16));
	for (; i < 28; i++) m3[3] = (byte)((m3[3] << 4) + Character.digit(aIDStr.charAt(i),16));
	for (; i < 30; i++) m3[4] = (byte)((m3[4] << 4) + Character.digit(aIDStr.charAt(i),16));
	for (; i < 32; i++) m3[5] = (byte)((m3[5] << 4) + Character.digit(aIDStr.charAt(i),16));
	for (; i < 34; i++) m3[6] = (byte)((m3[6] << 4) + Character.digit(aIDStr.charAt(i),16));
	for (; i < 36; i++) m3[7] = (byte)((m3[7] << 4) + Character.digit(aIDStr.charAt(i),16));
}	

Reproducible: Always
Comment 1 Grant Gayed CLA 2010-05-03 15:34:18 EDT
Created attachment 166859 [details]
final patch based on Car's feedback
Comment 2 Grant Gayed CLA 2010-05-03 15:35:48 EDT
fixed > 20100503