-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
play-json/shared/src/main/scala-2.13+/play/api/libs/json/JsObjectBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.api.libs.json | ||
|
||
import scala.collection.mutable.{ Builder => MBuilder } | ||
|
||
private[json] final class JsObjectBuilder | ||
extends MBuilder[(String, Json.JsValueWrapper), JsObject] { | ||
|
||
private val fs = Map.newBuilder[String, JsValue] | ||
|
||
def addOne(elem: (String, Json.JsValueWrapper)): this.type = { | ||
val (name, wrapped) = elem | ||
|
||
fs += (name -> Json.unwrap(wrapped)) | ||
|
||
this | ||
} | ||
|
||
override def addAll(xs: IterableOnce[(String, Json.JsValueWrapper)]): this.type = { | ||
xs.iterator.foreach(addOne) | ||
|
||
this | ||
} | ||
|
||
override def knownSize: Int = fs.knownSize | ||
|
||
override def sizeHint(size: Int): Unit = { | ||
fs.sizeHint(size) | ||
} | ||
|
||
def clear(): Unit = { | ||
fs.clear() | ||
} | ||
|
||
def result(): JsObject = JsObject(fs.result()) | ||
} |
35 changes: 35 additions & 0 deletions
35
play-json/shared/src/main/scala-2.13-/play/api/libs/json/JsObjectBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.api.libs.json | ||
|
||
import scala.collection.mutable.{ Builder => MBuilder } | ||
|
||
private[json] final class JsObjectBuilder | ||
extends MBuilder[(String, Json.JsValueWrapper), JsObject] { | ||
|
||
private val fs = Map.newBuilder[String, JsValue] | ||
|
||
def +=(elem: (String, Json.JsValueWrapper)): this.type = { | ||
val (name, wrapped) = elem | ||
|
||
fs += (name -> Json.unwrap(wrapped)) | ||
|
||
this | ||
} | ||
|
||
override def ++=(xs: TraversableOnce[(String, Json.JsValueWrapper)]): this.type = { | ||
xs.foreach(`+=`) | ||
|
||
this | ||
} | ||
|
||
def knownSize: Int = fs.result().size | ||
|
||
def clear(): Unit = { | ||
fs.clear() | ||
} | ||
|
||
def result(): JsObject = JsObject(fs.result()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters