Skip to content

Commit 052a924

Browse files
jdksjolencoleenp
authored andcommitted
8294293: Remove unused _width and _newlines field in outputStream
Reviewed-by: rehn, dholmes
1 parent c2ce43c commit 052a924

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/hotspot/share/utilities/ostream.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,29 @@
4343
extern "C" void jio_print(const char* s, size_t len);
4444
extern "C" int jio_printf(const char *fmt, ...);
4545

46-
outputStream::outputStream(int width) {
47-
_width = width;
46+
outputStream::outputStream() {
4847
_position = 0;
49-
_newlines = 0;
5048
_precount = 0;
5149
_indentation = 0;
5250
_scratch = NULL;
5351
_scratch_len = 0;
5452
}
5553

56-
outputStream::outputStream(int width, bool has_time_stamps) {
57-
_width = width;
54+
outputStream::outputStream(bool has_time_stamps) {
5855
_position = 0;
59-
_newlines = 0;
6056
_precount = 0;
6157
_indentation = 0;
6258
_scratch = NULL;
6359
_scratch_len = 0;
6460
if (has_time_stamps) _stamp.update();
6561
}
6662

67-
void outputStream::update_position(const char* s, size_t len) {
63+
bool outputStream::update_position(const char* s, size_t len) {
64+
bool saw_newline = false;
6865
for (size_t i = 0; i < len; i++) {
6966
char ch = s[i];
7067
if (ch == '\n') {
71-
_newlines += 1;
68+
saw_newline = true;
7269
_precount += _position + 1;
7370
_position = 0;
7471
} else if (ch == '\t') {
@@ -79,6 +76,7 @@ void outputStream::update_position(const char* s, size_t len) {
7976
_position += 1;
8077
}
8178
}
79+
return saw_newline;
8280
}
8381

8482
// Execute a vsprintf, using the given buffer if necessary.
@@ -400,7 +398,6 @@ void stringStream::zero_terminate() {
400398
void stringStream::reset() {
401399
assert(_is_frozen == false, "Modification forbidden");
402400
_written = 0; _precount = 0; _position = 0;
403-
_newlines = 0;
404401
zero_terminate();
405402
}
406403

@@ -893,17 +890,17 @@ void defaultStream::write(const char* s, size_t len) {
893890
intx holder = hold(thread_id);
894891

895892
if (DisplayVMOutput &&
896-
(_outer_xmlStream == NULL || !_outer_xmlStream->inside_attrs())) {
893+
(_outer_xmlStream == nullptr || !_outer_xmlStream->inside_attrs())) {
897894
// print to output stream. It can be redirected by a vfprintf hook
898895
jio_print(s, len);
899896
}
900897

901898
// print to log file
902-
if (has_log_file()) {
903-
int nl0 = _newlines;
904-
xmlTextStream::write(s, len);
899+
if (has_log_file() && _outer_xmlStream != nullptr) {
900+
_outer_xmlStream->write_text(s, len);
901+
bool nl = update_position(s, len);
905902
// flush the log file too, if there were any newlines
906-
if (nl0 != _newlines){
903+
if (nl) {
907904
flush();
908905
}
909906
} else {

src/hotspot/share/utilities/ostream.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ class outputStream : public ResourceObj {
4848

4949
protected:
5050
int _indentation; // current indentation
51-
int _width; // width of the page
52-
int _position; // position on the current line
53-
int _newlines; // number of '\n' output so far
54-
julong _precount; // number of chars output, less _position
51+
int _position; // visual position on the current line
52+
uint64_t _precount; // number of chars output, less than _position
5553
TimeStamp _stamp; // for time stamps
5654
char* _scratch; // internal scratch buffer for printf
5755
size_t _scratch_len; // size of internal scratch buffer
5856

59-
void update_position(const char* s, size_t len);
57+
// Returns whether a newline was seen or not
58+
bool update_position(const char* s, size_t len);
6059
static const char* do_vsnprintf(char* buffer, size_t buflen,
6160
const char* format, va_list ap,
6261
bool add_cr,
@@ -71,8 +70,8 @@ class outputStream : public ResourceObj {
7170

7271
public:
7372
// creation
74-
outputStream(int width = 80);
75-
outputStream(int width, bool has_time_stamps);
73+
outputStream();
74+
outputStream(bool has_time_stamps);
7675

7776
// indentation
7877
outputStream& indent();
@@ -86,7 +85,6 @@ class outputStream : public ResourceObj {
8685
void move_to(int col, int slop = 6, int min_space = 2);
8786

8887
// sizing
89-
int width() const { return _width; }
9088
int position() const { return _position; }
9189
julong count() const { return _precount + _position; }
9290
void set_count(julong count) { _precount = count - _position; }

0 commit comments

Comments
 (0)