package routing

import 

// cachedContextErr avoids repeatedly traversing context value wrappers in hot
// guarded loops. Standard cancellable contexts close Done before Err becomes
// observable; synthetic contexts without Done retain per-call Err polling.
func cachedContextErr( context.Context,  <-chan struct{}) error {
	if  == nil {
		return .Err()
	}
	select {
	case <-:
		return .Err()
	default:
		return nil
	}
}

// chargeSkippedRouteWork retains the logical work of a linear scan after its
// irrelevant prefix has been found by binary search. Nonstandard budgets and
// synthetic contexts retain exact step-by-step accounting and cancellation.
func chargeSkippedRouteWork( workBudget,  int) error {
	if  == nil ||  == 0 {
		return nil
	}
	,  := .(*routeSearchWorkGuard)
	if ! || .done == nil || .aggregate != nil && !.deferAggregate {
		for range  {
			if  := .step();  != nil {
				return 
			}
		}
		return nil
	}
	 := uint64()
	if .used >= .limit {
		return .step()
	}
	if  := .limit - .used;  >  {
		if  := .add();  != nil {
			return 
		}
		return .step()
	}
	return .add()
}