This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 116163

Summary: SourceFileObject keeps a snapshot of the source file in memory twice.
Product: java Reporter: Petr Nejedly <pnejedly>
Component: SourceAssignee: Jan Lahoda <jlahoda>
Status: RESOLVED FIXED    
Severity: blocker CC: issues, tzezula
Priority: P3 Keywords: PERFORMANCE, SIMPLEFIX
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: Fix

Description Petr Nejedly 2007-09-20 14:24:15 UTC
It is unnecessarily ineffective.
The source text is contained once in the String field "text", and second time parsed in the TokenHierarchy as a
CharBuffer. Since a CharBuffer over a String doesn't need to copy the content, slight change in the data flow can ensure
the data is shared and not duplicated.
I'll attach a patch for review. I did a few cleanups old code and tried to keep the semantic strictly equivalent, but if
you know the text can be cached in the Text field also in other cases (than ctor), you can simplify it more.

Also, in case that synchronized sections around accessing the text field are there only for proper inter-thread
communication, marking the field volatile instead would make the code more readable, as safe (even more - there's
currently no sync in ctor) and not blocking at all.
Comment 1 Petr Nejedly 2007-09-20 14:25:35 UTC
Created attachment 49165 [details]
Fix
Comment 2 Jan Lahoda 2007-09-20 15:07:21 UTC
Seems fine to me, feel free to commit it.
Comment 3 Petr Nejedly 2007-09-20 15:50:53 UTC
OK
java/source/src/org/netbeans/modules/java/source/parsing/SourceFileObject.java,v1.19