From b1738d682ea2bd7260438c543f30442cbc73a42c Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Wed, 20 Aug 2014 20:48:19 +0000 Subject: Rewritten some parts of code to increase the binary processing speed. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@391 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 9 +++++++++ src/arch/instruction.c | 2 +- src/glibext/gbufferline.c | 48 ++++++++++++++++++++++++++++++++++++++------ src/glibext/gbuffersegment.c | 39 ++++++++++++++++++++++++----------- 4 files changed, 79 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b02998..8e6da55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +14-08-20 Cyrille Bagard + + * src/arch/instruction.c: + Fix a bug by adding a missing 'return'. + + * src/glibext/gbufferline.c: + * src/glibext/gbuffersegment.c: + Rewrite some parts of code to increase the binary processing speed. + 14-08-19 Cyrille Bagard * configure.ac: diff --git a/src/arch/instruction.c b/src/arch/instruction.c index 95910ba..e1ee023 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -673,7 +673,7 @@ size_t g_arch_instruction_compute_group_index(GArchInstruction **iter, GArchInst const char *g_arch_instruction_get_keyword(const GArchInstruction *instr, AsmSyntax syntax) { - G_ARCH_INSTRUCTION_GET_CLASS(instr)->get_key(instr, syntax); + return G_ARCH_INSTRUCTION_GET_CLASS(instr)->get_key(instr, syntax); } diff --git a/src/glibext/gbufferline.c b/src/glibext/gbufferline.c index fbca259..6e06fe4 100644 --- a/src/glibext/gbufferline.c +++ b/src/glibext/gbufferline.c @@ -419,12 +419,17 @@ void g_buffer_line_fill_for_instr(GBufferLine *line, MemoryDataSize psize, Memor { size_t len; /* Taille de l'élément inséré */ VMPA_BUFFER(address); /* Adresse au format texte */ - char *bin_code; /* Tampon du code binaire */ + size_t required; /* Taille de traitement requise*/ + char static_buffer[64]; /* Petit tampon local rapide */ + char *bin_code; /* Tampon utilisé pour le code */ off_t start; /* Début de traitement */ off_t end; /* Limite de traitement */ off_t i; /* Boucle de parcours #1 */ char *iter; /* Boucle de parcours #2 */ int ret; /* Progression dans l'écriture */ + bin_t byte; /* Octet à représenter */ + + static const char *charset = "0123456789abcdef"; /* Adresse physique puis virtuelle */ @@ -434,25 +439,56 @@ void g_buffer_line_fill_for_instr(GBufferLine *line, MemoryDataSize psize, Memor vmpa2_virt_to_string(line->addr, vsize, address, &len); g_buffer_line_insert_text(line, BLC_VIRTUAL, address, len, RTT_RAW); - /* Code brut */ + /* Détermination du réceptacle */ + + required = length * 3 + 3; + + if (required <= sizeof(static_buffer)) + bin_code = static_buffer; + else + bin_code = (char *)calloc(required, sizeof(char)); - bin_code = (char *)calloc(length * 3 + 3, sizeof(char)); + /* Code brut */ start = get_phy_addr(line->addr); end = start + length; for (i = start, iter = bin_code; i < end; i++, iter += ret) { + byte = content[i]; + + iter[0] = charset[byte >> 4]; + iter[1] = charset[byte & 0x0f]; + if ((i + 1) < end) - ret = snprintf(iter, 4, "%02hhx ", content[i]); + { + iter[2] = ' '; + ret = 3; + } + else - ret = snprintf(iter, 6, "%02hhx%s", content[i], full ? "" : "..."); + { + if (full) + { + iter[2] = '\0'; + ret = 2; + } + else + { + strcpy(iter + 2, "..."); + ret = 5; + } + + } } + /* Conclusion */ + g_buffer_line_insert_text(line, BLC_BINARY, bin_code, iter - bin_code, RTT_RAW_CODE); - free(bin_code); + if (bin_code != static_buffer) + free(bin_code); } diff --git a/src/glibext/gbuffersegment.c b/src/glibext/gbuffersegment.c index e610a51..ff32e3c 100644 --- a/src/glibext/gbuffersegment.c +++ b/src/glibext/gbuffersegment.c @@ -55,7 +55,7 @@ typedef struct _rendering_pattern_t #define CAIRO_FONT_WEIGHT_COUNT 2 #define CAIRO_FONTS_COUNT (CAIRO_FONT_SLANT_COUNT * CAIRO_FONT_WEIGHT_COUNT) -#define CAIRO_FONT_INDEX(s, w) ((s) * CAIRO_FONT_SLANT_COUNT + (w)) +#define CAIRO_FONT_INDEX(s, w) ((s) + (w) * CAIRO_FONT_WEIGHT_COUNT) /* Fragment de caractères aux propriétés communes (instance) */ struct _GBufferSegment @@ -73,7 +73,7 @@ struct _GBufferSegment GdkColor alt_fg; /* Couleur d'impression bis */ GdkColor *used_fg; /* Couleur d'impression utile */ - cairo_text_extents_t extents; /* Dimensions du texte */ + gint x_advance; /* Dimensions du texte */ }; @@ -83,6 +83,7 @@ struct _GBufferSegmentClass GObjectClass parent; /* A laisser en premier */ cairo_t *font_ctxts[CAIRO_FONTS_COUNT]; /* Contextes de police */ + double x_advances[CAIRO_FONTS_COUNT]; /* Largeurs par caractère */ rendering_pattern_t patterns[RTT_COUNT];/* Modèles d'impression */ }; @@ -95,7 +96,7 @@ static void g_buffer_segment_class_init(GBufferSegmentClass *); static void g_buffer_segment_init(GBufferSegment *); /* Définit les dernières propriétés de rendu restantes. */ -static void g_buffer_segment_prepare(GBufferSegment *, const char *); +static void g_buffer_segment_prepare(GBufferSegment *, size_t); @@ -122,6 +123,7 @@ static void g_buffer_segment_class_init(GBufferSegmentClass *class) cairo_font_weight_t w; /* Boucle de parcours #2 */ cairo_t **cr; /* Contexte à créer */ cairo_surface_t *surface; /* Surface pour dessin Cairo */ + cairo_text_extents_t extents; /* Couverture des caractères */ /* Contextes pour les mesures initiales */ @@ -140,8 +142,22 @@ static void g_buffer_segment_class_init(GBufferSegmentClass *class) cairo_select_font_face(*cr, "mono", s, w); cairo_set_font_size(*cr, 13); + cairo_text_extents(*cr, "A", &extents); + class->x_advances[CAIRO_FONT_INDEX(s, w)] = extents.x_advance; + + + printf("s=%d w=%d ==>> %g vs %g\n", s, w, + extents.x_advance, class->x_advances[CAIRO_FONT_INDEX(s, w)]); + + printf(" >> %d\n", CAIRO_FONT_INDEX(s, w)); + + + printf("[x] = %g [0] = %g\n", class->x_advances[CAIRO_FONT_INDEX(s, w)], class->x_advances[0]); + } + printf("class=%p [0]=%g\n", class, class->x_advances[0]); + g_free(filename); /* Propriétés d'impression */ @@ -245,7 +261,7 @@ GBufferSegment *g_buffer_segment_new(RenderingTagType type, const char *text, si class = G_BUFFER_SEGMENT_GET_CLASS(result); result->pattern = &class->patterns[type]; - g_buffer_segment_prepare(result, text); + g_buffer_segment_prepare(result, length); g_buffer_segment_set_style(result, SRS_CLASSIC); @@ -267,12 +283,11 @@ GBufferSegment *g_buffer_segment_new(RenderingTagType type, const char *text, si * * ******************************************************************************/ -static void g_buffer_segment_prepare(GBufferSegment *segment, const char *text) +static void g_buffer_segment_prepare(GBufferSegment *segment, size_t length) { GBufferSegmentClass *class; /* Classe associée à l'instance*/ cairo_font_slant_t slant; /* Style d'impression */ cairo_font_weight_t weight; /* Poids de la police */ - cairo_t *cr; /* Contexte de rendu */ /* Taille */ @@ -281,9 +296,7 @@ static void g_buffer_segment_prepare(GBufferSegment *segment, const char *text) slant = segment->pattern->slant; weight = segment->pattern->weight; - cr = class->font_ctxts[CAIRO_FONT_INDEX(slant, weight)]; - - cairo_text_extents(cr, text, &segment->extents); + segment->x_advance = class->x_advances[CAIRO_FONT_INDEX(slant, weight)] * length; /* Couleurs */ @@ -354,7 +367,7 @@ const char *g_buffer_segment_get_text(const GBufferSegment *segment) gint g_buffer_segment_get_width(const GBufferSegment *segment) { - return segment->extents.x_advance; + return segment->x_advance; } @@ -470,7 +483,7 @@ void g_buffer_segment_draw(GBufferSegment *segment, cairo_t *cairo, gint *x, gin segment->cache_bg.green / 65535.0, segment->cache_bg.blue / 65535.0); - cairo_rectangle(cairo, *x, y, segment->extents.x_advance, 17); + cairo_rectangle(cairo, *x, y, segment->x_advance, 17); cairo_set_operator(cairo, CAIRO_OPERATOR_DIFFERENCE); cairo_fill(cairo); @@ -501,13 +514,15 @@ void g_buffer_segment_draw(GBufferSegment *segment, cairo_t *cairo, gint *x, gin cairo_font_extents(cairo, &extents); +#if 1 if (extents.descent != 3) printf("FONT : %g, %g\n", extents.ascent, extents.descent); +#endif cairo_show_text(cairo, segment->text); //printf(">> %s >> %f %f\n", segment->text, segment->extents.width, segment->extents.x_advance); - *x += segment->extents.x_advance; + *x += segment->x_advance; } -- cgit v0.11.2-87-g4458