pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: lukaseder (@lukaseder) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #3865: Avoid well known slow JDK libraries String.format() and DecimalFormat in PGInterval::getValue to get drastic performance boost
Date: Fri, 14 Nov 2025 08:08:55 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

> Well the except part is kinda important. It will probably break something

Sure, you can remove the trailing zeros like this:

```java
while (sb.charAt(sb.length() - 1) == '0')
  sb.deleteCharAt(sb.length() - 1);
```

So:

```java
  public String getValue() {
    if (isNull) {
      return null;
    }

    StringBuilder sb = new StringBuilder();
    sb.append(years).append(" years ")
      .append(months).append(" mons ")
      .append(days).append(" days ")
      .append(hours).append(" hours ")
      .append(minutes).append(" mins ");

    if (wholeSeconds < 0 || microSeconds < 0)
      sb.append('-');

    sb.append(Math.abs(wholeSeconds));

    if (microSeconds != 0) {
      sb.append('.');
      String s = "" + Math.abs(microSeconds);

      for (int i = s.length(); i < 6; i++)
        sb.append('0');

      sb.append(s);

      while (sb.charAt(sb.length() - 1) == '0')
        sb.deleteCharAt(sb.length() - 1);
    }

    sb.append(" secs");
    return sb.toString();
  }
```

view thread (4+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #3865: Avoid well known slow JDK libraries String.format() and DecimalFormat in PGInterval::getValue to get drastic performance boost
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox