Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 311129 - [Browser][Mozilla]Code refactoring of Parse method in nsID class
Summary: [Browser][Mozilla]Code refactoring of Parse method in nsID class
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.6 RC1   Edit
Assignee: Grant Gayed CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-29 23:37 EDT by pei na CLA
Modified: 2010-05-03 15:35 EDT (History)
1 user (show)

See Also:
carolynmacleod4: review+


Attachments
final patch based on Car's feedback (3.95 KB, patch)
2010-05-03 15:34 EDT, Grant Gayed CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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