diff options
| author | mergify[bot] | 2022-03-30 23:58:32 +0000 |
|---|---|---|
| committer | GitHub | 2022-03-30 23:58:32 +0000 |
| commit | 157d5c3e37058286539867ca9a33b8bc1c6e43e3 (patch) | |
| tree | 2c27fb55e08fef316bdec1a312d917515d822760 /core/src/main/scala | |
| parent | 4e8f362c399f85b93bce4175562670242d8411b1 (diff) | |
Use var List instead of ListBuffer to save memory (#2465) (#2467)
This reduces memory use of every HasId by 64 bytes.
Every instance of HasId (including all Data) had 2 ListBuffer vals for
recording post-naming hooks, yet this feature is almost never used.
These are now vars of type List which allows the common case of Nil to
add no incremental memory use per instance of HasId.
(cherry picked from commit cf410180ac8de854d8d7ecf89f4813ac8541dcdb)
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'core/src/main/scala')
| -rw-r--r-- | core/src/main/scala/chisel3/internal/Builder.scala | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/core/src/main/scala/chisel3/internal/Builder.scala b/core/src/main/scala/chisel3/internal/Builder.scala index 1ffe54ab..d9ac8cc5 100644 --- a/core/src/main/scala/chisel3/internal/Builder.scala +++ b/core/src/main/scala/chisel3/internal/Builder.scala @@ -115,10 +115,10 @@ private[chisel3] trait HasId extends InstanceId { private var prefix_seed: Prefix = Nil // Post-seed hooks called to carry the suggested seeds to other candidates as needed - private val suggest_postseed_hooks = scala.collection.mutable.ListBuffer.empty[String => Unit] + private var suggest_postseed_hooks: List[String => Unit] = Nil // Post-seed hooks called to carry the auto seeds to other candidates as needed - private val auto_postseed_hooks = scala.collection.mutable.ListBuffer.empty[String => Unit] + private var auto_postseed_hooks: List[String => Unit] = Nil /** Takes the last seed suggested. Multiple calls to this function will take the last given seed, unless * this HasId is a module port (see overridden method in Data.scala). @@ -136,7 +136,7 @@ private[chisel3] trait HasId extends InstanceId { // Bypass the overridden behavior of autoSeed in [[Data]], apply autoSeed even to ports private[chisel3] def forceAutoSeed(seed: String): this.type = { auto_seed = Some(seed) - for (hook <- auto_postseed_hooks) { hook(seed) } + for (hook <- auto_postseed_hooks.reverse) { hook(seed) } prefix_seed = Builder.getPrefix this } @@ -154,7 +154,7 @@ private[chisel3] trait HasId extends InstanceId { def suggestName(seed: => String): this.type = { if (suggested_seed.isEmpty) suggested_seed = Some(seed) prefix_seed = Builder.getPrefix - for (hook <- suggest_postseed_hooks) { hook(seed) } + for (hook <- suggest_postseed_hooks.reverse) { hook(seed) } this } @@ -211,8 +211,8 @@ private[chisel3] trait HasId extends InstanceId { private[chisel3] def hasAutoSeed: Boolean = auto_seed.isDefined - private[chisel3] def addSuggestPostnameHook(hook: String => Unit): Unit = suggest_postseed_hooks += hook - private[chisel3] def addAutoPostnameHook(hook: String => Unit): Unit = auto_postseed_hooks += hook + private[chisel3] def addSuggestPostnameHook(hook: String => Unit): Unit = suggest_postseed_hooks ::= hook + private[chisel3] def addAutoPostnameHook(hook: String => Unit): Unit = auto_postseed_hooks ::= hook // Uses a namespace to convert suggestion into a true name // Will not do any naming if the reference already assigned. |
