88 * You must not remove this notice, or any other, from this software.
99 **/
1010
11- /**
12- * Author: David Miller
13- **/
14-
1511using System ;
1612using System . Reflection ;
1713using System . Reflection . Emit ;
@@ -23,7 +19,7 @@ public class EmptyExpr : Expr
2319 #region Data
2420
2521 readonly object _coll ;
26- public object Coll { get { return _coll ; } }
22+ public object Coll => _coll ;
2723
2824 #endregion
2925
@@ -38,24 +34,20 @@ public EmptyExpr(object coll)
3834
3935 #region Type mangling
4036
41- public bool HasClrType
42- {
43- get { return true ; }
44- }
37+ public bool HasClrType => true ;
4538
4639 public Type ClrType
4740 {
48- get {
49- if ( _coll is IPersistentList )
50- return typeof ( IPersistentList ) ;
51- else if ( _coll is IPersistentVector )
52- return typeof ( IPersistentVector ) ;
53- else if ( _coll is IPersistentMap )
54- return typeof ( IPersistentMap ) ;
55- else if ( _coll is IPersistentSet )
56- return typeof ( IPersistentSet ) ;
57- else
58- throw new InvalidOperationException ( "Unknown Collection type." ) ;
41+ get
42+ {
43+ return _coll switch
44+ {
45+ IPersistentList => typeof ( IPersistentList ) ,
46+ IPersistentVector => typeof ( IPersistentVector ) ,
47+ IPersistentMap => typeof ( IPersistentMap ) ,
48+ IPersistentSet => typeof ( IPersistentSet ) ,
49+ _ => throw new InvalidOperationException ( "Unknown Collection type." )
50+ } ;
5951 }
6052 }
6153
@@ -79,21 +71,29 @@ public object Eval()
7971
8072 public void Emit ( RHC rhc , ObjExpr objx , CljILGen ilg )
8173 {
82- if ( _coll is IPersistentList || _coll is LazySeq ) // JVM does not include LazySeq test. I'm getting it in some places. LazySeq of 0 size got us here, we'll treat as an empty list
83- ilg . EmitFieldGet ( ListEmptyFI ) ;
84- else if ( _coll is IPersistentVector )
85- ilg . EmitFieldGet ( VectorEmptyFI ) ;
86- else if ( _coll is IPersistentMap )
87- ilg . EmitFieldGet ( HashMapEmptyFI ) ;
88- else if ( _coll is IPersistentSet )
89- ilg . EmitFieldGet ( HashSetEmptyFI ) ;
90- else
91- throw new InvalidOperationException ( "Unknown collection type." ) ;
74+ switch ( _coll )
75+ {
76+ case IPersistentList :
77+ case LazySeq :
78+ ilg . EmitFieldGet ( ListEmptyFI ) ;
79+ break ;
80+ case IPersistentVector :
81+ ilg . EmitFieldGet ( VectorEmptyFI ) ;
82+ break ;
83+ case IPersistentMap :
84+ ilg . EmitFieldGet ( HashMapEmptyFI ) ;
85+ break ;
86+ case IPersistentSet :
87+ ilg . EmitFieldGet ( HashSetEmptyFI ) ;
88+ break ;
89+ default :
90+ throw new InvalidOperationException ( "Unknown collection type." ) ;
91+ }
9292 if ( rhc == RHC . Statement )
9393 ilg . Emit ( OpCodes . Pop ) ;
9494 }
9595
96- public bool HasNormalExit ( ) { return true ; }
96+ public bool HasNormalExit ( ) => true ;
9797
9898 #endregion
9999 }
0 commit comments