List for cgit developers and users
 help / color / mirror / Atom feed
From: hjemli at gmail.com (Lars Hjemli)
Subject: [PATCH] move LCS table away from the stack
Date: Wed, 14 Sep 2011 08:38:29 +0200	[thread overview]
Message-ID: <CAFXTnz6=p2cUfTR6baBdasUn2ugznUbWQ+=-Gz7b6YbYeVVTDQ@mail.gmail.com> (raw)
In-Reply-To: <1315701862-30457-2-git-send-email-jamie.couture@gmail.com>

On Sun, Sep 11, 2011 at 02:44, Jamie Couture <jamie.couture at gmail.com> wrote:
> +/*
> + * ssdiff line limits
> + */
> +#ifndef MAX_SSDIFF_M
> +#define MAX_SSDIFF_M 1024
> +#endif
> +
> +#ifndef MAX_SSDIFF_N
> +#define MAX_SSDIFF_N 1024
> +#endif
> +#define MAX_SSDIFF_SIZE ((MAX_SSDIFF_M) * (MAX_SSDIFF_N))

I think this limit should be more like 128*128 for a few reasons:
* ss-diff for lines longer than 128 chars probably isn't very useful
(you'd need a very wide monitor)
* cpu time spent in LCS() seems to be propotional to avg(linelength)^2


> ?static char *longest_common_subsequence(char *A, char *B)
> ?{
> ? ? ? ?int i, j, ri;
> ? ? ? ?int m = strlen(A);
> ? ? ? ?int n = strlen(B);
> - ? ? ? int L[m + 1][n + 1];
> - ? ? ? int tmp1, tmp2;
> + ? ? ? int **L;
> + ? ? ? int tmp1, tmp2, length;
> ? ? ? ?int lcs_length;
> ? ? ? ?char *result;
>
> + ? ? ? length = (m + 1) * (n + 1);
> +
> + ? ? ? // We bail if the lines are too long
> + ? ? ? if (length > MAX_SSDIFF_SIZE)
> + ? ? ? ? ? ? ? return NULL;
> +
> + ? ? ? L = create_lcs_table(m + 1, n + 1);
> +
> ? ? ? ?for (i = m; i >= 0; i--) {
> ? ? ? ? ? ? ? ?for (j = n; j >= 0; j--) {
> ? ? ? ? ? ? ? ? ? ? ? ?if (A[i] == '\0' || B[j] == '\0') {
> @@ -59,6 +84,9 @@ static char *longest_common_subsequence(char *A, char *B)
> ? ? ? ? ? ? ? ? ? ? ? ?j += 1;
> ? ? ? ? ? ? ? ?}
> ? ? ? ?}
> +
> + ? ? ? free(*L);
> + ? ? ? free(L);
> ? ? ? ?return result;
> ?}

This function is potentially invoked for each diff-line, right? If so,
why not prepare a "shared" lcs-table in the caller (expecting
worst-case linelength) to avoid the setup/teardown of the table for
each line?

--
larsh




  reply	other threads:[~2011-09-14  6:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-09  4:43 [PATCH 0/1] segfault in cgit jamie.couture
2011-09-09  4:43 ` [PATCH 1/1] move LCS table away from the stack jamie.couture
2011-09-11  0:44   ` jamie.couture
2011-09-11  0:44     ` [PATCH] " jamie.couture
2011-09-14  6:38       ` hjemli [this message]
2011-09-17 22:25         ` [PATCH 1/1] " jamie.couture
2012-01-03 15:12           ` hjemli
2012-01-04  8:59             ` normalperson
2012-01-04 16:57               ` jamie.couture
2012-01-12  3:38               ` jamie.couture
2012-01-12  3:38                 ` [PATCH 1/2] correct length check for LCS table jamie.couture
2012-01-12  3:38                 ` [PATCH 2/2] use correct type for sizeof jamie.couture
2012-03-18  9:22                   ` hjemli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFXTnz6=p2cUfTR6baBdasUn2ugznUbWQ+=-Gz7b6YbYeVVTDQ@mail.gmail.com' \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).