Skip to content
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

Declare constants properly #403

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object HijrahDateConfigurator {
private val PATH_SEP: String = File.pathSeparator

/** Default config file name. */
private val DEFAULT_CONFIG_FILENAME: String = "hijrah_deviation.cfg"
private final val DEFAULT_CONFIG_FILENAME = "hijrah_deviation.cfg"

/** Default path to the config file. */
private val DEFAULT_CONFIG_PATH: String = s"org${FILE_SEP}threeten${FILE_SEP}bp${FILE_SEP}chrono"
Expand Down
6 changes: 3 additions & 3 deletions core/shared/src/main/scala/org/threeten/bp/Duration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ object Duration {
lazy val ZERO: Duration = new Duration(0, 0)

/** Constant for nanos per second. */
private def NANOS_PER_SECOND: Int = 1000000000
private final val NANOS_PER_SECOND = 1000000000
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure these don't affect js size?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to reason about this.

Previously, every time this constant was used it would require a function call to NANOS_PER_SECOND. This requires a function NANOS_PER_SECOND to be emitted in the JS. This also means it's harder for the JS runtime to optimize it.

Now the generated JS code will never have NANOS_PER_SECOND in it. This is because before emitting JS code the Scala compiler will replace all the uses directly with 1000000000.


/** Constant for nanos per milli. */
private def NANOS_PER_MILLI: Int = 1000000
private final val NANOS_PER_MILLI = 1000000

/** Constant for nanos per second. */
private def BI_NANOS_PER_SECOND: BigInteger = BigInteger.valueOf(NANOS_PER_SECOND.toLong)

/** The pattern for parsing. */
private def PATTERN: Pattern =
private lazy val PATTERN: Pattern =
Pattern.compile(
"([-+]?)P(?:([-+]?[0-9]+)D)?" + "(T(?:([-+]?[0-9]+)H)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)(?:[.,]([0-9]{0,9}))?S)?)?",
Pattern.CASE_INSENSITIVE
Expand Down
24 changes: 12 additions & 12 deletions core/shared/src/main/scala/org/threeten/bp/LocalTime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,40 @@ object LocalTime {
lazy val NOON: LocalTime = HOURS(12)

/** Hours per day. */
private[bp] val HOURS_PER_DAY: Int = 24
private[bp] final val HOURS_PER_DAY = 24

/** Minutes per hour. */
private[bp] val MINUTES_PER_HOUR: Int = 60
private[bp] final val MINUTES_PER_HOUR = 60

/** Minutes per day. */
private[bp] val MINUTES_PER_DAY: Int = MINUTES_PER_HOUR * HOURS_PER_DAY
private[bp] final val MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY

/** Seconds per minute. */
private[bp] val SECONDS_PER_MINUTE: Int = 60
private[bp] final val SECONDS_PER_MINUTE = 60

/** Seconds per hour. */
private[bp] val SECONDS_PER_HOUR: Int = SECONDS_PER_MINUTE * MINUTES_PER_HOUR
private[bp] final val SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR

/** Seconds per day. */
private[bp] val SECONDS_PER_DAY: Int = SECONDS_PER_HOUR * HOURS_PER_DAY
private[bp] final val SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY

/** Milliseconds per day. */
private[bp] val MILLIS_PER_DAY: Long = SECONDS_PER_DAY * 1000L
private[bp] final val MILLIS_PER_DAY = SECONDS_PER_DAY * 1000L

/** Microseconds per day. */
private[bp] val MICROS_PER_DAY: Long = SECONDS_PER_DAY * 1000000L
private[bp] final val MICROS_PER_DAY = SECONDS_PER_DAY * 1000000L

/** Nanos per second. */
private[bp] val NANOS_PER_SECOND: Long = 1000000000L
private[bp] final val NANOS_PER_SECOND = 1000000000L

/** Nanos per minute. */
private[bp] val NANOS_PER_MINUTE: Long = NANOS_PER_SECOND * SECONDS_PER_MINUTE
private[bp] final val NANOS_PER_MINUTE = NANOS_PER_SECOND * SECONDS_PER_MINUTE

/** Nanos per hour. */
private[bp] val NANOS_PER_HOUR: Long = NANOS_PER_MINUTE * MINUTES_PER_HOUR
private[bp] final val NANOS_PER_HOUR = NANOS_PER_MINUTE * MINUTES_PER_HOUR

/** Nanos per day. */
private[bp] val NANOS_PER_DAY: Long = NANOS_PER_HOUR * HOURS_PER_DAY
private[bp] final val NANOS_PER_DAY = NANOS_PER_HOUR * HOURS_PER_DAY

/**
* Obtains the current time from the system clock in the default time-zone.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,40 @@ import org.threeten.bp.temporal.ValueRange
private[chrono] object ChronoLocalDateTimeImpl {

/** Hours per minute. */
private val HOURS_PER_DAY: Int = 24
private final val HOURS_PER_DAY = 24

/** Minutes per hour. */
private val MINUTES_PER_HOUR: Int = 60
private final val MINUTES_PER_HOUR = 60

/** Minutes per day. */
private val MINUTES_PER_DAY: Int = MINUTES_PER_HOUR * HOURS_PER_DAY
private final val MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY

/** Seconds per minute. */
private val SECONDS_PER_MINUTE: Int = 60
private final val SECONDS_PER_MINUTE = 60

/** Seconds per hour. */
private val SECONDS_PER_HOUR: Int = SECONDS_PER_MINUTE * MINUTES_PER_HOUR
private final val SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR

/** Seconds per day. */
private val SECONDS_PER_DAY: Int = SECONDS_PER_HOUR * HOURS_PER_DAY
private final val SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY

/** Milliseconds per day. */
private val MILLIS_PER_DAY: Long = SECONDS_PER_DAY * 1000L
private final val MILLIS_PER_DAY = SECONDS_PER_DAY * 1000L

/** Microseconds per day. */
private val MICROS_PER_DAY: Long = SECONDS_PER_DAY * 1000000L
private final val MICROS_PER_DAY = SECONDS_PER_DAY * 1000000L

/** Nanos per second. */
private val NANOS_PER_SECOND: Long = 1000000000L
private final val NANOS_PER_SECOND = 1000000000L

/** Nanos per minute. */
private val NANOS_PER_MINUTE: Long = NANOS_PER_SECOND * SECONDS_PER_MINUTE
private final val NANOS_PER_MINUTE = NANOS_PER_SECOND * SECONDS_PER_MINUTE

/** Nanos per hour. */
private val NANOS_PER_HOUR: Long = NANOS_PER_MINUTE * MINUTES_PER_HOUR
private final val NANOS_PER_HOUR = NANOS_PER_MINUTE * MINUTES_PER_HOUR

/** Nanos per day. */
private val NANOS_PER_DAY: Long = NANOS_PER_HOUR * HOURS_PER_DAY
private final val NANOS_PER_DAY = NANOS_PER_HOUR * HOURS_PER_DAY

/**
* Obtains an instance of {@code ChronoLocalDateTime} from a date and time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ import org.threeten.bp.temporal.ValueRange
object HijrahDate {

/** The minimum valid year-of-era. */
val MIN_VALUE_OF_ERA: Int = 1
final val MIN_VALUE_OF_ERA = 1

/**
* The maximum valid year-of-era. This is currently set to 9999 but may be changed to increase the
* valid range in a future version of the specification.
*/
val MAX_VALUE_OF_ERA: Int = 9999
final val MAX_VALUE_OF_ERA = 9999

/**
* 0-based, for number of day-of-year in the beginning of month in normal year.
Expand Down Expand Up @@ -106,12 +106,12 @@ object HijrahDate {
/**
* Position of day-of-month. This value is used to get the min/max value from an array.
*/
private val POSITION_DAY_OF_MONTH: Int = 5
private final val POSITION_DAY_OF_MONTH = 5

/**
* Position of day-of-year. This value is used to get the min/max value from an array.
*/
private val POSITION_DAY_OF_YEAR: Int = 6
private final val POSITION_DAY_OF_YEAR = 6

/** Zero-based start date of cycle year. */
private lazy val CYCLEYEAR_START_DATE: Array[Int] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import org.threeten.bp.ZoneOffset
object StandardZoneRules {

/** The last year to have its transitions cached. */
private val LAST_CACHED_YEAR: Int = 2100
private final val LAST_CACHED_YEAR = 2100

/**
* Creates an instance.
Expand Down