RFR: 8260198: TypeInstPtr::dump2() emits multiple lines if Verbose is set [v4]
Xin Liu
xliu at openjdk.java.net
Sat Feb 20 08:35:38 UTC 2021
On Wed, 17 Feb 2021 19:23:14 GMT, Evgeny Astigeevich <github.com+42899633+eastig at openjdk.org> wrote:
>> Another option:
>> class filterStringStream: public stringStream {
>> private:
>> char ch;
>> public:
>> filterStringStream(char ch_to_filter, size_t initial_bufsize = 256) : stringStream(initial_bufsize), ch(ch_to_filter) {}
>>
>> virtual void write(const char* c, size_t len) override {
>> const char* e = c + len;
>> while (c != e) {
>> size_t i = 0;
>> while ((c+i) != e && c[i] != ch ) {
>> ++i;
>> }
>> stringStream::write(c, i);
>> c += i;
>> while (c != e && *ch == ch) {
>> ++c;
>> }
>> }
>> }
>> };
>>
>> Your code will be:
>> filterStringStream ss('\n');
>> ss.print(" ");
>> const_oop->print_oop(&ss);
>> st->print_raw(ss.base(), ss,size());
>
>> `tr_delete` is expensive. Also deleting something in a stream does not fit into a concept of streams.
>> I see that the content of `ss` is traversed many times.
>> What about this code:
>>
>> ```
>> for (const char *str = ss.base(); *str; ) {
>> size_t i = 0;
>> while (str[i] && str[i] != '\n' ) {
>> ++i;
>> }
>> st->print_raw(str, i);
>> str += i;
>> while (*str == '\n') {
>> ++str;
>> }
>> }
>> ```
>
> You can put this code in a function like `print_filtering_ch(char, const stringStream&, outputStream*)`
hi, @eastig ,
Thank you for reviewing this code.
you are right, I shouldn't modify the contents of a stringStream. I treated it as a buffer instead of stream.
I took you advice, I moved `tr_delete` logic to StringUtils, which is a toolkit class.
Could you take a look again?
-------------
PR: https://git.openjdk.java.net/jdk/pull/2178
More information about the hotspot-compiler-dev
mailing list