Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I might need to optimize this XD

I might need to optimize this XD

Scheduled Pinned Locked Moved The Lounge
regexquestioncode-review
24 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H honey the codewitch

    Look away. Here's almost all of it. The stuff you don't see is very thin

    public static int Run(int[][] prog,LexContext input)
    {
    input.EnsureStarted();
    int i,match=-1;
    _Fiber[] currentFibers, nextFibers, tmp;
    int currentFiberCount=0, nextFiberCount=0;
    int[] pc;
    // position in input
    int sp=0;
    // stores our captured input
    var sb = new StringBuilder(64);
    int[] saved, matched;
    saved = new int[2];
    currentFibers = new _Fiber[prog.Length];
    nextFibers = new _Fiber[prog.Length];
    _EnqueueFiber(ref currentFiberCount, ref currentFibers, new _Fiber(prog,0, saved), 0);
    matched = null;
    var cur = -1;
    if (LexContext.EndOfInput != input.Current)
    {
    var ch1 = unchecked((char)input.Current);
    if (char.IsHighSurrogate(ch1))
    {
    if (-1 == input.Advance())
    throw new ExpectingException("Expecting low surrogate in unicode stream. The input source is corrupt or not valid Unicode", input.Line, input.Column, input.Position, input.FileOrUrl);
    var ch2 = unchecked((char)input.Current);
    cur = char.ConvertToUtf32(ch1, ch2);
    }
    else
    cur = ch1;

    }
    		
    while(0
    
    J Offline
    J Offline
    Jorgen Andersson
    wrote on last edited by
    #21

    Oh, no wonder then, you're doing it on purpose... :laugh:

    Wrong is evil and must be defeated. - Jeff Ello

    H 1 Reply Last reply
    0
    • J Jorgen Andersson

      Oh, no wonder then, you're doing it on purpose... :laugh:

      Wrong is evil and must be defeated. - Jeff Ello

      H Offline
      H Offline
      honey the codewitch
      wrote on last edited by
      #22

      Doing what on purpose? I'm a little slow this morning. :)

      Real programmers use butterflies

      J 1 Reply Last reply
      0
      • H honey the codewitch

        Doing what on purpose? I'm a little slow this morning. :)

        Real programmers use butterflies

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #23

        Spawning loads of fibers. Or is this auto generated code again?

        Wrong is evil and must be defeated. - Jeff Ello

        H 1 Reply Last reply
        0
        • J Jorgen Andersson

          Spawning loads of fibers. Or is this auto generated code again?

          Wrong is evil and must be defeated. - Jeff Ello

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #24

          Well, it's not on purpose per se. I mean yes, I'm spawning a lot of them, but the idea is to keep as few active or "alive" at one time as possible. when I see a jmp with 3 operands it spawns 2 fibers in addition to a primary fiber. That's what I don't want, since every fiber has to examine the character under the cursor which leads to many examinations of the same character. There's no way to optimize this out because it's rather the point of the fiber running in the first place. Multiple examinations are a byproduct of the NFA algorithm. My goal is simply to reduce/eliminate the amount of jmps and especially the number of operands they have. A pure DFA can run by examining each character only once.

          Real programmers use butterflies

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups