summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorwl <wl>2010-12-20 06:39:01 +0000
committerwl <wl>2010-12-20 06:39:01 +0000
commitb706a783c204610a8d7fe9b024644fc45d20a4df (patch)
treea0101bbdae0d9e0d872e3465019489576fc6e190 /src
parentfa1faa789de9aafcdff1575c4e3f56ed96929a22 (diff)
downloadgroff-b706a783c204610a8d7fe9b024644fc45d20a4df.tar.gz
Speed up access to cflags values.
We now recompute the cflags values for all charinfo objects if `.class' has been called. * src/roff/troff/charinfo.h: Add external references to `class_flag' and `get_flags'. (charinfo): `get_flags' no longer has a return value. (charinfo::overlaps_horizontally, charinfo::overlaps_vertically, charinfo::can_break_before, charinfo::can_break_after, charinfo::can_break_after, charinfo::ends_sentence, charinfo::transparent,, charinfo:ignore_hcodes, charinfo::prohibit_break_before, charinfo::prohibit_break_after, charinfo::inter_char_space): Call global `get_flags' only if necessary. (charinfo::add_to_class): Set `class_flag'. * src/roff/troff/input.cpp (class_flag): New global flag. (charinfo::charinfo): Call `get_flags' member function. (get_flags): New global function which iterates over all entries in the charinfo dictionary. (charinfo::get_flags): Set `flags' directly.
Diffstat (limited to 'src')
-rw-r--r--src/roff/troff/charinfo.h48
-rw-r--r--src/roff/troff/input.cpp29
2 files changed, 58 insertions, 19 deletions
diff --git a/src/roff/troff/charinfo.h b/src/roff/troff/charinfo.h
index 3e07662f..4624aa34 100644
--- a/src/roff/troff/charinfo.h
+++ b/src/roff/troff/charinfo.h
@@ -21,6 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <vector>
#include <utility>
+extern int class_flag; // set if there was a call to `.class'
+extern void get_flags();
+
class macro;
class charinfo : glyph {
@@ -86,7 +89,7 @@ public:
int get_translation_input();
charinfo *get_translation(int = 0);
void set_translation(charinfo *, int, int);
- unsigned int get_flags();
+ void get_flags();
void set_flags(unsigned int);
void set_special_translation(int, int);
int get_special_translation(int = 0);
@@ -116,52 +119,72 @@ charinfo *get_charinfo_by_number(int);
inline int charinfo::overlaps_horizontally()
{
- return get_flags() & OVERLAPS_HORIZONTALLY;
+ if (class_flag)
+ ::get_flags();
+ return flags & OVERLAPS_HORIZONTALLY;
}
inline int charinfo::overlaps_vertically()
{
- return get_flags() & OVERLAPS_VERTICALLY;
+ if (class_flag)
+ ::get_flags();
+ return flags & OVERLAPS_VERTICALLY;
}
inline int charinfo::can_break_before()
{
- return get_flags() & BREAK_BEFORE;
+ if (class_flag)
+ ::get_flags();
+ return flags & BREAK_BEFORE;
}
inline int charinfo::can_break_after()
{
- return get_flags() & BREAK_AFTER;
+ if (class_flag)
+ ::get_flags();
+ return flags & BREAK_AFTER;
}
inline int charinfo::ends_sentence()
{
- return get_flags() & ENDS_SENTENCE;
+ if (class_flag)
+ ::get_flags();
+ return flags & ENDS_SENTENCE;
}
inline int charinfo::transparent()
{
- return get_flags() & TRANSPARENT;
+ if (class_flag)
+ ::get_flags();
+ return flags & TRANSPARENT;
}
inline int charinfo::ignore_hcodes()
{
- return get_flags() & IGNORE_HCODES;
+ if (class_flag)
+ ::get_flags();
+ return flags & IGNORE_HCODES;
}
inline int charinfo::prohibit_break_before()
{
- return get_flags() & DONT_BREAK_BEFORE;
+ if (class_flag)
+ ::get_flags();
+ return flags & DONT_BREAK_BEFORE;
}
inline int charinfo::prohibit_break_after()
{
- return get_flags() & DONT_BREAK_AFTER;
+ if (class_flag)
+ ::get_flags();
+ return flags & DONT_BREAK_AFTER;
}
inline int charinfo::inter_char_space()
{
- return get_flags() & INTER_CHAR_SPACE;
+ if (class_flag)
+ ::get_flags();
+ return flags & INTER_CHAR_SPACE;
}
inline int charinfo::numbered()
@@ -255,6 +278,7 @@ inline symbol *charinfo::get_symbol()
inline void charinfo::add_to_class(int c)
{
+ class_flag = 1;
// TODO ranges cumbersome for single characters?
ranges.push_back(std::pair<int, int>(c, c));
}
@@ -262,11 +286,13 @@ inline void charinfo::add_to_class(int c)
inline void charinfo::add_to_class(int lo,
int hi)
{
+ class_flag = 1;
ranges.push_back(std::pair<int, int>(lo, hi));
}
inline void charinfo::add_to_class(charinfo *ci)
{
+ class_flag = 1;
nested_classes.push_back(ci);
}
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index b6e73ed7..7a0f46ce 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -83,6 +83,7 @@ void transparent_file();
token tok;
int break_flag = 0;
+int class_flag = 0;
int color_flag = 1; // colors are on by default
static int backtrace_flag = 0;
#ifndef POPEN_MISSING
@@ -8477,6 +8478,7 @@ charinfo::charinfo(symbol s)
{
index = next_index++;
number = -1;
+ get_flags();
}
int charinfo::get_unicode_code()
@@ -8507,25 +8509,36 @@ void charinfo::set_translation(charinfo *ci, int tt, int ti)
transparent_translate = tt;
}
+// Recompute flags for all entries in the charinfo dictionary.
+void get_flags()
+{
+ dictionary_iterator iter(charinfo_dictionary);
+ charinfo *ci;
+ symbol s;
+ while (iter.get(&s, (void **)&ci)) {
+ assert(!s.is_null());
+ ci->get_flags();
+ }
+ class_flag = 0;
+}
+
// Get the union of all flags affecting this charinfo.
-unsigned int charinfo::get_flags()
+void charinfo::get_flags()
{
- unsigned int all_flags = flags;
dictionary_iterator iter(char_class_dictionary);
- charinfo *cp;
+ charinfo *ci;
symbol s;
- while (iter.get(&s, (void **)&cp)) {
+ while (iter.get(&s, (void **)&ci)) {
assert(!s.is_null());
- if (cp->contains(get_unicode_code())) {
+ if (ci->contains(get_unicode_code())) {
#if defined(DEBUGGING)
if (debug_state)
fprintf(stderr, "charinfo::get_flags %p %s %d\n",
- (void *)cp, cp->nm.contents(), cp->flags);
+ (void *)ci, ci->nm.contents(), ci->flags);
#endif
- all_flags |= cp->flags;
+ flags |= ci->flags;
}
}
- return all_flags;
}
void charinfo::set_special_translation(int c, int tt)