-
-
-/**
- Do break substitution in S, using CRITERION. Return new value.
- CRITERION is either a SMOB pointer to the desired line, or a number
- representing the break direction. Do not modify SRC.
-
- It is rather tightly coded, since it takes a lot of time; it is
- one of the top functions in the profile.
-
-*/
-SCM
-Grob::handle_broken_grobs (SCM src, SCM criterion)
-{
- again:
- Grob *sc = unsmob_grob (src);
- if (sc)
- {
- if (SCM_INUMP (criterion))
- {
- Item * i = dynamic_cast<Item*> (sc);
- Direction d = to_dir (criterion);
- if (i && i->break_status_dir () != d)
- {
- Item *br = i->find_prebroken_piece (d);
- return (br) ? br->self_scm () : SCM_UNDEFINED;
- }
- }
- else
- {
- Line_of_score * line
- = dynamic_cast<Line_of_score*> (unsmob_grob (criterion));
- if (sc->line_l () != line)
- {
- sc = sc->find_broken_piece (line);
-
- }
-
- /* now: !sc || (sc && sc->line_l () == line) */
- if (!sc)
- return SCM_UNDEFINED;
-
- /* now: sc && sc->line_l () == line */
- if (!line)
- return sc->self_scm();
- /*
- This was introduced in 1.3.49 as a measure to prevent
- programming errors. It looks expensive (?). TODO:
- benchmark , document when (what kind of programming
- errors) this happens.
- */
- if (sc->common_refpoint (line, X_AXIS)
- && sc->common_refpoint (line, Y_AXIS))
- {
- return sc->self_scm ();
- }
- return SCM_UNDEFINED;
- }
- }
- else if (ly_pair_p (src)) // SCM_CONSP (src)) // huh?
- {
- SCM oldcar =ly_car (src);
- /*
- UGH! breaks on circular lists.
- */
- SCM newcar = handle_broken_grobs (oldcar, criterion);
- SCM oldcdr = ly_cdr (src);
-
- if (newcar == SCM_UNDEFINED
- && (gh_pair_p (oldcdr) || oldcdr == SCM_EOL))
- {
- /*
- This is tail-recursion, ie.
-
- return handle_broken_grobs (cdr, criterion);
-
- We don't want to rely on the compiler to do this. Without
- tail-recursion, this easily crashes with a stack overflow. */
- src = oldcdr;
- goto again;
- }
-
- SCM newcdr = handle_broken_grobs (oldcdr, criterion);
- return scm_cons (newcar, newcdr);
- }
- else
- return src;
-
- return src;
-}
-