Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3931956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:24:13+00:00 2026-05-19T23:24:13+00:00

Today I opened one of Microsoft’ .Net regex implementations and it hit me that

  • 0

Today I opened one of Microsoft’ .Net regex implementations and it hit me that this may be the only reason for the existence of the goto statement in a language like C# (which puts major emphasis on the ‘clarity for the developer’ concept where goto seems to have no place at all) and possibly also the sole reason why Microsoft use it the CLR libraries implementations – for performance boosts. I also remember seeing similar optimization in the Microsoft’s ASP.NET page/control rendering in System.Web.UI.dll as well. Would that be a valid (or documented maybe ?) assumption to make? Have you seen it used by Microsoft under any other circumstances except to improve code execution time? Thanks.

Below is an excerpt (NOT MEANT TO EXAMINED IN DETAIL JUST SCAN OVER IT) from Microsoft’s own regex implementation where they again use goto extensively for what appears to be only performance boost:

public override void Go() 
{
    int num4;
    int num5;
    string runtext = base.runtext;
    int runtextstart = base.runtextstart;
    int runtextbeg = base.runtextbeg;
    int runtextend = base.runtextend;
    int runtextpos = base.runtextpos;
    int[] runtrack = base.runtrack;
    int runtrackpos = base.runtrackpos;
    int[] runstack = base.runstack;
    int runstackpos = base.runstackpos;
    runtrack[--runtrackpos] = runtextpos;
    runtrack[--runtrackpos] = 0;
    runstack[--runstackpos] = runtextpos;
    runtrack[--runtrackpos] = 1;
    if ((((runtextpos != base.runtextstart) || 
       (4 > (runtextend - runtextpos))) || 
       ((runtext[runtextpos] != '<') || 
       (runtext[runtextpos + 1] != '%'))) || 
       ((runtext[runtextpos + 2] != '-') || 
       (runtext[runtextpos + 3] != '-')))
    {
        goto Label_02F8;
    }
    runtextpos += 4;
    runstack[--runstackpos] = -1;
    runtrack[--runtrackpos] = 1;
    goto Label_0213;
Label_0161:
    if (num5 > num4)
    {
        runtrack[--runtrackpos] = (num5 - num4) - 1;
        runtrack[--runtrackpos] = runtextpos - 1;
        runtrack[--runtrackpos] = 2;
    }
Label_0194:
    num4 = runstack[runstackpos++];
    this.Capture(2, num4, runtextpos);
    runtrack[--runtrackpos] = num4;
    runtrack[--runtrackpos] = 3;
    if (runtextpos >= runtextend)
    {
        goto Label_02F8;
    }
    runtextpos++;
    if (runtext[runtextpos] != '-')
    {
        goto Label_02F8;
    }
    num4 = runstack[runstackpos++];
    this.Capture(1, num4, runtextpos);
    runtrack[--runtrackpos] = num4;
    runtrack[--runtrackpos] = 3;
Label_0213:
    if (num4 != -1)
    {
        runtrack[--runtrackpos] = num4;
    }
    else
    {
        runtrack[--runtrackpos] = runtextpos;
    }
    if ((num4 = runstack[runstackpos++]) != runtextpos)
    {
        runtrack[--runtrackpos] = runtextpos;
        runtrack[--runtrackpos] = 4;
    }
    else
    {
        runstack[--runstackpos] = num4;
        runtrack[--runtrackpos] = 5;
    }
    if (((3 > (runtextend - runtextpos)) || 
    (runtext[runtextpos] != '-')) || 
    ((runtext[runtextpos + 1] != '%') || 
    (runtext[runtextpos + 2] != '>')))
    {
        goto Label_02F8;
    }
    runtextpos += 3;
    num4 = runstack[runstackpos++];
    this.Capture(0, num4, runtextpos);
    runtrack[--runtrackpos] = num4;
    runtrack[--runtrackpos] = 3;
Label_02EF:
    base.runtextpos = runtextpos;
    return;
Label_02F8:
    base.runtrackpos = runtrackpos;
    base.runstackpos = runstackpos;
    this.EnsureStorage();
    runtrackpos = base.runtrackpos;
    runstackpos = base.runstackpos;
    runtrack = base.runtrack;
    runstack = base.runstack;
    switch (runtrack[runtrackpos++])
    {
        case 1:
            runstackpos++;
            goto Label_02F8;

        case 2:
            runtextpos = runtrack[runtrackpos++];
            num4 = runtrack[runtrackpos++];
            if (num4 > 0)
            {
                runtrack[--runtrackpos] = num4 - 1;
                runtrack[--runtrackpos] = runtextpos - 1;
                runtrack[--runtrackpos] = 2;
            }
            goto Label_0194;

        case 3:
            runstack[--runstackpos] = runtrack[runtrackpos++];
            this.Uncapture();
            goto Label_02F8;

        case 4:
            runtextpos = runtrack[runtrackpos++];
            runstack[--runstackpos] = runtextpos;
            runtrack[--runtrackpos] = 5;
            if ((runtrackpos > 40) && (runstackpos > 30))
            {
                runstack[--runstackpos] = runtextpos;
                runtrack[--runtrackpos] = 1;
                runstack[--runstackpos] = runtextpos;
                runtrack[--runtrackpos] = 1;
                num4 = (num5 = runtextend - runtextpos) + 1;
                do
                {
                    if (--num4 <= 0)
                    {
                        goto Label_0161;
                    }
                    runtextpos++;
                }
                while (runtext[runtextpos] != '-');
                runtextpos--;
                goto Label_0161;
            }
            runtrack[--runtrackpos] = 6;
            goto Label_02F8;

        case 5:
            runstack[runstackpos] = runtrack[runtrackpos++];
            goto Label_02F8;
    }
    runtextpos = runtrack[runtrackpos++];
    goto Label_02EF;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:24:14+00:00Added an answer on May 19, 2026 at 11:24 pm

    One use-case I see is auto-generated code. The high-level control flow constructs are easy for us humans, but not necessarily convenient as output of code generation algorithms.

    And is your code decompiled? In that case it might just be written in a way that the decompiler can’t deal with without using gotos. On IL level all control flow constructs are translated to gotos, and the decompiler tries to guess what they were. And in complicated cases it might not figure out a good way to represent it using high-level constructs and thus resorts to gotos.

    Another use-case are state-machines. You have a number of states, and after each one it can transit to a new state using goto statements. Parsers are a common application of state-machines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today, I ran into this weird problem with a user using Mac OS X.
Today I was listening to the Hanselminutes show about .NET 3.5 SP1...What's inside ,
Today I discovered that my fresh installation of Apache HTTP Server is able to
Today somebody told me that interface implementation in C# is just Can-Do relationship, not
Today I was working on a tab navigation for a webpage. I tried the
Today I had a coworker suggest I refactor my code to use a label
Today I stumbled about a Problem which seems to be a bug in the
Today at work we came across the following code (some of you might recognize
Today when I was in computer organization class, teacher talked about something interesting to
Today I had a discussion with a colleague about nested functions in Javascript: function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.