-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK-8236048: Cleanup use of Utils.normalizeNewlines #9691
JDK-8236048: Cleanup use of Utils.normalizeNewlines #9691
Conversation
👋 Welcome back jjg! A progress list of the required criteria for merging this PR into |
@jonathan-gibbons The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks quite good. Apart from the inline comments, I wondered about the following:
- Would the methods and constant you moved to
Text
be better placed inContent
as they are used in other Content instances? - There are quite a few uses of the
"\n"
string literal in a content or pre-content context where theNL
constant couuld be used.
...jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocument.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Text.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/RawHtml.java
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/RawHtml.java
Show resolved
Hide resolved
@jonathan-gibbons This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 26 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit 1b756bf.
Your commit was automatically rebased without conflicts. |
@jonathan-gibbons Pushed as commit 1b756bf. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review a medium-size cleanup related to handling newlines in
Content
/HtmlTree
/Text[Builder]
trees.This is the 3rd and last in the recent series of cleanup tasks in the code to generate HTML.
Until recently, the
Text
/TextBuilder
objects were "ready-for-writing", meaning that characters like<
,&
, etc were encoded as entities, and newlines were represented by the platform line separator. This caused difficulties when counting the size of generated text, since these characters had to be detected and accounted for. A recent change addressed entities, but stayed clear of the newline issue, which is now addressed here.A related performance problem is that the method
Utils.normalizeNewlines
always created new strings, even when it was not necessary.With this change, newlines in
Text
,TextBuilder
and other subtypes ofContent
containing text are always represented by\n
, and are converted to the platform line separator as needed.I note the following assumptions:
\n
on Linux and macOS,\r\n
on Windows etc.)Together, these imply that some amount of the input will need to be scanned to normalize newlines at some point in the process. While it would be nice to not have to normalize newlines, it's a case or "pay now, or pay later".
Notable parts of this change:
Utils.normalizeNewlines
is moved to be a static method inText
and rewritten to not create new strings unless needed. This allows a number of questionable imports oftoolkit.utils.DocletConstants
to be removed from thehtml.markup
package. While it would be possible to call this method automatically on all strings passed toText
,TextBuilder
etc, in many cases it is not necessary: put another way, it only needs to be called on strings that have come from the user, either in documentation comments or in command-line options.Content.write
, and the implementations thereof, are given a new parameter which gives the newline sequence to use. This is set to\n
fortoString
and the platform separator when writing to a file.DocletConstants.NL
goes away and is superseded by:Text.NL
: always\n
, to be used when adding text to aContent
tree (this replaces most uses ofDocletConstants.NL
)DocFile.PLATFORM_LINE_SEPARATOR
: the platform line separator, to be used when writing to filescharCount
methods no longer have to worry about use of the platform line separator\r
characters added intoText
/TextBuilder
/RawHtml
/Content
Other cleanup:
DocletConstants.DEFAULT_TAB_STOP_LENGTH
is moved toBaseOptions
which is the only class that uses it. This leaves just two remaining constants inDocletConstants
which should probably be moved elsewhere as well, and theDocletConstants
class deleted. That is a step too far for the work here.One test was affected by the
DocletConstants.NL
change, but apart from that, this is a pure-cleanup change, with no (intentional) externally visible effect.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9691/head:pull/9691
$ git checkout pull/9691
Update a local copy of the PR:
$ git checkout pull/9691
$ git pull https://git.openjdk.org/jdk pull/9691/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9691
View PR using the GUI difftool:
$ git pr show -t 9691
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9691.diff