@@ -2365,7 +2365,6 @@ LINE_SET Pkb::getTransitiveNextStatements(LINE_NO lineNo,
2365
2365
LINE_SET transitiveStatements =
2366
2366
getTransitiveNextStatements (next, lineNosVisited);
2367
2367
result.merge (transitiveStatements);
2368
- lineNosVisited.merge (transitiveStatements);
2369
2368
}
2370
2369
}
2371
2370
}
@@ -2392,7 +2391,6 @@ LINE_SET Pkb::getTransitivePrevStatements(LINE_NO lineNo,
2392
2391
LINE_SET transitiveStatements =
2393
2392
getTransitivePrevStatements (prev, lineNosVisited);
2394
2393
result.merge (transitiveStatements);
2395
- lineNosVisited.merge (transitiveStatements);
2396
2394
}
2397
2395
}
2398
2396
}
@@ -2404,12 +2402,6 @@ LINE_SET Pkb::getTransitivePrevStatements(LINE_NO lineNo,
2404
2402
2405
2403
bool Pkb::affects (LineNumber line1, LineNumber line2) {
2406
2404
LINE_SET affectedStatements = getAffectedStatements (line1.number );
2407
-
2408
- // add to cache if it's not in cache
2409
- if (affectsTableCache.map .find (line1.number ) == affectsTableCache.map .end ()) {
2410
- affectsTableCache.insert (std::pair (line1.number , affectedStatements));
2411
- }
2412
-
2413
2405
return affectedStatements.find (line2.number ) != affectedStatements.end ();
2414
2406
}
2415
2407
@@ -2418,24 +2410,12 @@ LINE_SET Pkb::affects(LineNumber line, Statement statement) {
2418
2410
if (!statement.type .has_value () ||
2419
2411
statement.type .value () == StatementType::Assign) {
2420
2412
result = getAffectedStatements (line.number );
2421
-
2422
- // add to cache if it's not in cache
2423
- if (affectsTableCache.map .find (line.number ) ==
2424
- affectsTableCache.map .end ()) {
2425
- affectsTableCache.insert (std::pair (line.number , result));
2426
- }
2427
2413
}
2428
2414
return result;
2429
2415
}
2430
2416
2431
2417
bool Pkb::affects (LineNumber line, Underscore underscore) {
2432
2418
LINE_SET affectedStatements = getAffectedStatements (line.number );
2433
-
2434
- // add to cache if it's not in cache
2435
- if (affectsTableCache.map .find (line.number ) == affectsTableCache.map .end ()) {
2436
- affectsTableCache.insert (std::pair (line.number , affectedStatements));
2437
- }
2438
-
2439
2419
return !affectedStatements.empty ();
2440
2420
}
2441
2421
@@ -2444,12 +2424,6 @@ LINE_SET Pkb::affects(Statement statement, LineNumber line) {
2444
2424
if (!statement.type .has_value () ||
2445
2425
statement.type .value () == StatementType::Assign) {
2446
2426
result = getAffectorStatements (line.number );
2447
-
2448
- // add to cache if it's not in cache
2449
- if (invertAffectsTableCache.map .find (line.number ) ==
2450
- invertAffectsTableCache.map .end ()) {
2451
- invertAffectsTableCache.insert (std::pair (line.number , result));
2452
- }
2453
2427
}
2454
2428
return result;
2455
2429
}
@@ -2472,8 +2446,9 @@ LINE_LINE_PAIRS Pkb::affects(Statement statement1, Statement statement2) {
2472
2446
// only need to compute and cache entry if its not already inside
2473
2447
// cache table.
2474
2448
if (affectsTableCache.map .find (line) == affectsTableCache.map .end ()) {
2475
- LINE_SET affectedStatements = getAffectedStatements (line);
2476
- affectsTableCache.insert (std::pair (line, affectedStatements));
2449
+ // adding to cache is done within the called function. So we only
2450
+ // have to call the function to get it cached.
2451
+ getAffectedStatements (line);
2477
2452
}
2478
2453
}
2479
2454
@@ -2515,11 +2490,6 @@ LINE_SET Pkb::affects(Statement statement, Underscore underscore) {
2515
2490
if (!affectedStatements.empty ()) {
2516
2491
result.insert (line);
2517
2492
}
2518
-
2519
- // add into cache if its not in cache
2520
- if (affectsTableCache.map .find (line) == affectsTableCache.map .end ()) {
2521
- affectsTableCache.insert (std::pair (line, affectedStatements));
2522
- }
2523
2493
}
2524
2494
}
2525
2495
}
@@ -2528,13 +2498,6 @@ LINE_SET Pkb::affects(Statement statement, Underscore underscore) {
2528
2498
2529
2499
bool Pkb::affects (Underscore underscore, LineNumber line) {
2530
2500
LINE_SET affectorStatements = getAffectorStatements (line.number );
2531
-
2532
- // add into cache if its not in cache
2533
- if (invertAffectsTableCache.map .find (line.number ) ==
2534
- invertAffectsTableCache.map .end ()) {
2535
- invertAffectsTableCache.insert (std::pair (line.number , affectorStatements));
2536
- }
2537
-
2538
2501
return !affectorStatements.empty ();
2539
2502
}
2540
2503
@@ -2554,12 +2517,6 @@ LINE_SET Pkb::affects(Underscore underscore, Statement statement) {
2554
2517
if (!affectorStatements.empty ()) {
2555
2518
result.insert (line);
2556
2519
}
2557
-
2558
- // add into cache if its not in cache
2559
- if (invertAffectsTableCache.map .find (line) ==
2560
- invertAffectsTableCache.map .end ()) {
2561
- invertAffectsTableCache.insert (std::pair (line, affectorStatements));
2562
- }
2563
2520
}
2564
2521
}
2565
2522
}
@@ -2573,12 +2530,6 @@ bool Pkb::affects(Underscore underscore1, Underscore underscore2) {
2573
2530
2574
2531
for (LINE_NO line : assignments) {
2575
2532
LINE_SET affectedStatements = getAffectedStatements (line);
2576
-
2577
- // add into cache if its not in cache
2578
- if (affectsTableCache.map .find (line) == affectsTableCache.map .end ()) {
2579
- affectsTableCache.insert (std::pair (line, affectedStatements));
2580
- }
2581
-
2582
2533
if (!affectedStatements.empty ()) {
2583
2534
return true ;
2584
2535
}
@@ -2604,6 +2555,9 @@ LINE_SET Pkb::getAffectedStatements(LINE_NO lineNo) {
2604
2555
for (NEXT next : nexts) {
2605
2556
result.merge (getAffectedAux (modifiedVar, next, {}));
2606
2557
}
2558
+
2559
+ // add to cache before returning result.
2560
+ affectsTableCache.insert (std::pair (lineNo, result));
2607
2561
}
2608
2562
}
2609
2563
}
@@ -2711,6 +2665,9 @@ LINE_SET Pkb::getAffectorStatements(LINE_NO lineNo) {
2711
2665
result.merge (getAffectorAux (var, prev, {}));
2712
2666
}
2713
2667
}
2668
+
2669
+ // add to cache before returning result.
2670
+ invertAffectsTableCache.insert (std::pair (lineNo, result));
2714
2671
}
2715
2672
}
2716
2673
}
@@ -2920,7 +2877,6 @@ LINE_SET Pkb::getTransitiveAffectedStatements(LINE_NO lineNo,
2920
2877
LINE_SET transitiveStatements =
2921
2878
getTransitiveAffectedStatements (assignment, lineNosVisited);
2922
2879
result.merge (transitiveStatements);
2923
- lineNosVisited.merge (transitiveStatements);
2924
2880
}
2925
2881
}
2926
2882
}
@@ -2945,7 +2901,6 @@ LINE_SET Pkb::getTransitiveAffectorStatements(LINE_NO lineNo,
2945
2901
LINE_SET transitiveStatements =
2946
2902
getTransitiveAffectorStatements (assignment, lineNosVisited);
2947
2903
result.merge (transitiveStatements);
2948
- lineNosVisited.merge (transitiveStatements);
2949
2904
}
2950
2905
}
2951
2906
}
0 commit comments