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 - SourceFileObject keeps a snapshot of the source file in memory twice.
Summary: SourceFileObject keeps a snapshot of the source file in memory twice.
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Jan Lahoda
Depends on:
Reported: 2007-09-20 14:24 UTC by Petr Nejedly
Modified: 2007-09-20 15:50 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:

Fix (3.91 KB, patch)
2007-09-20 14:25 UTC, Petr Nejedly
Details | Diff

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