Skip to content

Commit 2f01ed8

Browse files
committed
Simplify case* analysis
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
1 parent 07c3f9c commit 2f01ed8

2 files changed

Lines changed: 6 additions & 334 deletions

File tree

pkg/compiler/analyze.go

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,24 +1410,12 @@ func (a *Analyzer) parseCaseStar(form interface{}, env Env) (*ast.Node, error) {
14101410

14111411
// Build skip check set
14121412
skipCheckSet := make(map[int64]bool)
1413-
if skipCheck != nil {
1413+
if !lang.IsNil(skipCheck) {
14141414
if set, ok := skipCheck.(IPersistentSet); ok {
14151415
for seq := Seq(set); seq != nil; seq = seq.Next() {
14161416
val := First(seq)
1417-
switch key := val.(type) {
1418-
case int64:
1419-
skipCheckSet[key] = true
1420-
case int:
1421-
skipCheckSet[int64(key)] = true
1422-
case int32:
1423-
skipCheckSet[int64(key)] = true
1424-
case uint32:
1425-
skipCheckSet[int64(key)] = true
1426-
case uint64:
1427-
skipCheckSet[int64(key)] = true
1428-
case uint:
1429-
skipCheckSet[int64(key)] = true
1430-
}
1417+
valInt := lang.AsInt64(val)
1418+
skipCheckSet[valInt] = true
14311419
}
14321420
}
14331421
}
@@ -1440,23 +1428,7 @@ func (a *Analyzer) parseCaseStar(form interface{}, env Env) (*ast.Node, error) {
14401428
val := mapEntry.Val()
14411429

14421430
// Convert key to int64
1443-
var keyInt int64
1444-
switch k := key.(type) {
1445-
case int64:
1446-
keyInt = k
1447-
case int:
1448-
keyInt = int64(k)
1449-
case int32:
1450-
keyInt = int64(k)
1451-
case uint32:
1452-
keyInt = int64(k)
1453-
case uint64:
1454-
keyInt = int64(k)
1455-
case uint:
1456-
keyInt = int64(k)
1457-
default:
1458-
return nil, exInfo(fmt.Sprintf("case* map key must be integer, got %T", key), nil)
1459-
}
1431+
keyInt := lang.AsInt64(key)
14601432

14611433
// Extract the vector [test-constant result-expr]
14621434
if Count(val) != 2 {
@@ -1471,32 +1443,8 @@ func (a *Analyzer) parseCaseStar(form interface{}, env Env) (*ast.Node, error) {
14711443
// without comparison (they contain condp expressions for collision handling)
14721444
hasCollision := false
14731445

1474-
// Check if the map key is in the skip check set
1475-
switch k := key.(type) {
1476-
case int64:
1477-
if _, isCollision := skipCheckSet[k]; isCollision {
1478-
hasCollision = true
1479-
}
1480-
case int:
1481-
if _, isCollision := skipCheckSet[int64(k)]; isCollision {
1482-
hasCollision = true
1483-
}
1484-
case int32:
1485-
if _, isCollision := skipCheckSet[int64(k)]; isCollision {
1486-
hasCollision = true
1487-
}
1488-
case uint32:
1489-
if _, isCollision := skipCheckSet[int64(k)]; isCollision {
1490-
hasCollision = true
1491-
}
1492-
case uint64:
1493-
if _, isCollision := skipCheckSet[int64(k)]; isCollision {
1494-
hasCollision = true
1495-
}
1496-
case uint:
1497-
if _, isCollision := skipCheckSet[int64(k)]; isCollision {
1498-
hasCollision = true
1499-
}
1446+
if _, isCollision := skipCheckSet[keyInt]; isCollision {
1447+
hasCollision = true
15001448
}
15011449

15021450
// Analyze the test constant and result expression

pkg/compiler/analyze_test.go

Lines changed: 0 additions & 276 deletions
This file was deleted.

0 commit comments

Comments
 (0)