Skip to content

Commit 75c703c

Browse files
committed
Apply suggestions from PR feedback
1 parent de4f0f5 commit 75c703c

5 files changed

Lines changed: 341 additions & 169 deletions

File tree

src/main/java/com/amazon/ion/impl/IonManagedWriterEncodingContext_1_1.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ internal class IonManagedWriterEncodingContext_1_1 {
9393
* make sure that any prior e-expressions are still valid. In addition, we would need to re-export all
9494
* the other macros from `_` (the default module).
9595
* - For now, we're just throwing an Exception.
96-
*
97-
* Visible for testing.
9896
*/
99-
fun getOrAssignMacroAddressAndName(name: String, macro: MacroImpl): Int {
97+
private fun getOrAssignMacroAddressAndName(name: String, macro: MacroImpl): Int {
10098
// TODO: This is O(n), but could be O(1).
10199
var existingAddress = macroNames.indexOf(name)
102100
if (existingAddress < 0) {
@@ -131,7 +129,7 @@ internal class IonManagedWriterEncodingContext_1_1 {
131129
* 2. Check newMacros, if found, return that address
132130
* 3. Add to newMacros, return new address
133131
*/
134-
fun getOrAssignMacroAddress(macro: MacroImpl): Int {
132+
private fun getOrAssignMacroAddress(macro: MacroImpl): Int {
135133
var address = macroTable.getOrDefault(macro, -1)
136134
if (address >= 0) return address
137135
address = newMacros.getOrDefault(macro, -1)
@@ -140,6 +138,13 @@ internal class IonManagedWriterEncodingContext_1_1 {
140138
return assignMacroAddress(macro)
141139
}
142140

141+
fun getOrAssignMacroAddress(macro: MacroImpl, name: String?): Int {
142+
return if (name == null)
143+
getOrAssignMacroAddress(macro)
144+
else
145+
getOrAssignMacroAddressAndName(name, macro)
146+
}
147+
143148
fun getMacroNameForId(id: Int): String? = macroNames[id]
144149

145150
/** Unconditionally adds a macro to the macro table data structures and returns the new address. */

src/main/java/com/amazon/ion/impl/IonManagedWriterOptions_1_1.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ internal class ManagedWriterOptions_1_1(
3232
BY_NAME,
3333
BY_ADDRESS,
3434
}
35+
36+
val useMacroNames = eExpressionIdentifierStrategy == EExpressionIdentifierStrategy.BY_NAME
3537
}
3638

3739
/**

0 commit comments

Comments
 (0)