@@ -62,6 +62,7 @@ public class MTMathAtomFactory {
62
62
" rfloor " : " \u{230B} "
63
63
]
64
64
65
+ private static let delimValueLock = NSLock ( )
65
66
static var _delimValueToName = [ String: String] ( )
66
67
public static var delimValueToName : [ String : String ] {
67
68
if _delimValueToName. isEmpty {
@@ -78,7 +79,11 @@ public class MTMathAtomFactory {
78
79
}
79
80
output [ value] = key
80
81
}
81
- _delimValueToName = output
82
+ delimValueLock. lock ( )
83
+ defer { delimValueLock. unlock ( ) }
84
+ if _delimValueToName. isEmpty {
85
+ _delimValueToName = output
86
+ }
82
87
}
83
88
return _delimValueToName
84
89
}
@@ -98,6 +103,7 @@ public class MTMathAtomFactory {
98
103
" widetilde " : " \u{0303} "
99
104
]
100
105
106
+ private static let accentValueLock = NSLock ( )
101
107
static var _accentValueToName : [ String : String ] ? = nil
102
108
public static var accentValueToName : [ String : String ] {
103
109
if _accentValueToName == nil {
@@ -115,7 +121,11 @@ public class MTMathAtomFactory {
115
121
}
116
122
output [ value] = key
117
123
}
118
- _accentValueToName = output
124
+ accentValueLock. lock ( )
125
+ defer { accentValueLock. unlock ( ) }
126
+ if _accentValueToName == nil {
127
+ _accentValueToName = output
128
+ }
119
129
}
120
130
return _accentValueToName!
121
131
}
@@ -390,6 +400,7 @@ public class MTMathAtomFactory {
390
400
" scriptscriptstyle " : MTMathStyle ( style: . scriptOfScript) ,
391
401
]
392
402
403
+ private static let textToLatexLock = NSLock ( )
393
404
static var _textToLatexSymbolName : [ String : String ] ? = nil
394
405
public static var textToLatexSymbolName : [ String : String ] {
395
406
get {
@@ -413,13 +424,17 @@ public class MTMathAtomFactory {
413
424
}
414
425
output [ atom. nucleus] = key
415
426
}
416
- self . _textToLatexSymbolName = output
427
+ textToLatexLock. lock ( )
428
+ defer { textToLatexLock. unlock ( ) }
429
+ if self . _textToLatexSymbolName == nil {
430
+ self . _textToLatexSymbolName = output
431
+ }
417
432
}
418
433
return self . _textToLatexSymbolName!
419
434
}
420
- set {
421
- self . _textToLatexSymbolName = newValue
422
- }
435
+ // set {
436
+ // self._textToLatexSymbolName = newValue
437
+ // }
423
438
}
424
439
425
440
// public static let sharedInstance = MTMathAtomFactory()
@@ -603,8 +618,13 @@ public class MTMathAtomFactory {
603
618
e.g. to define a symbol for "lcm" one can call:
604
619
`MTMathAtomFactory.add(latexSymbol:"lcm", value:MTMathAtomFactory.operatorWithName("lcm", limits: false))` */
605
620
public static func add( latexSymbol name: String , value: MTMathAtom ) {
621
+ let _ = Self . textToLatexSymbolName
622
+ // above force textToLatexSymbolName to instantiate first, _textToLatexSymbolName also initialized.
623
+ textToLatexLock. lock ( )
624
+ defer { textToLatexLock. unlock ( ) }
606
625
supportedLatexSymbols [ name] = value
607
- Self . textToLatexSymbolName [ value. nucleus] = name
626
+ // below update the underlying dictionary entry.
627
+ Self . _textToLatexSymbolName ? [ value. nucleus] = name
608
628
}
609
629
610
630
/** Returns a large opertor for the given name. If limits is true, limits are set up on
0 commit comments