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
P

Payton Byrd 2023

@Payton Byrd 2023
About
Posts
5
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Okay, old guys unite, what smartphone do you have?
    P Payton Byrd 2023

    I'm going to sound hip and old at the same time. To me, the height of cell phones was the Lumia 850XL with Windows 10. Since then, I've been forced to choose between Android and iOS, so I pick Android. I use Square Home as my launcher because it gives you the best "Windows 10-like" experience. I've heard of people using Windows 10 on a Surface Duo, which may be ok, but what I would really want is Windows 11 + Windows Subsystem for Android. But I need a phone that isn't a DIY project, so I got the next best thing, which is a Samsung Galaxy Z-Fold 5. Someday the screens on these phones won't break for no reason, and when that happens I will get one for my main phone and tinker with my Z-Fold 5.

    The Lounge ios mobile question

  • Microsoft, do you know how many people are complaining?
    P Payton Byrd 2023

    This is the most entitled thing I have read in a long time.

    The Lounge com data-structures question discussion

  • I had been looking for ideas for a code generator
    P Payton Byrd 2023

    This seems like the worst idea ever. Not only do you have not insight into the training of the model in the nuget package, but you also need to capture the generated source to see what's being compiled into your code. Throw a build pipeline and obfuscation on top and you have the perfectly opaque platform for distributing just about any kind of malware.

    The Lounge design csharp visual-studio com graphics

  • There are many gotos, but these ones are mine
    P Payton Byrd 2023

    Without the full code I didn't know what the logic inside of the various labelled location did, so I simply returned the current substring as a FAMatch. Your method dumps out as an FAMatch so I defaulted to that behavior. The point is that inlined local methods are going to be just as fast as gotos and the pattern matching is much more efficient.

    The Lounge

  • There are many gotos, but these ones are mine
    P Payton Byrd 2023

    Code runs in LinqPad. Code runs in LinqPad. This should be significantly faster than your original code because it speeds up the conditionals by using pattern matching instead of overloadable operators. Also, the local functions can be in-lined, meaning they will be executed in place, which is even more efficient than the `Goto` statements. And now it's not pure spaghetti.

    string json = """
    {
      "test": 0,
      "data": "value"
    }
    """;
    
    JsonStringRunner runner = new();
    
    List matches = new();
    FAMatch current = default;
    Stopwatch sw = new();
    sw.Start();
    do{
        current = runner.GetMatch(json);
        matches.Add(current);
    } while(!runner.isDone);
    sw.Stop();
    matches.Dump();
    sw.Dump();
    
    internal record struct FAMatch(int token, string match, int position, int length, int column)
    {
        internal static FAMatch Create(int token, string match, int position, int length, int column)
            => new(token, match, position, length, column);
    }
    
    internal abstract class FAStringRunner
    {
        protected int position = -1, line = 0, column = 0;
        internal bool isDone = false;
    }
    
    internal sealed partial class JsonStringRunner : FAStringRunner
    {
        private void Advance(string s, ref int ch, ref int len, bool flag)
        {
            // Assuming Advance takes consecutive characters in the string.
            ch = s\[position\];
            position++;
            len++;
            isDone = !(position < s.Length);
        }
        private FAMatch NextMatchImpl(string s)
        {
            int ch;
            int len;
            int l;
            int c;
            ch = -1;
            len = 0;
            if ((this.position is -1))
            {
                this.position = 0;
            }
            int p = this.position;
            l = this.line;
            c = this.column;
            this.Advance(s, ref ch, ref len, true);
            // q0:
            switch (ch)
            {
                // \[\\t-\\n\\r \]
                case 9 or 10 or 13 or 32:
                    if(ch is 10 or 13){
                        l = line++;
                    }
                    return q1();
                // \[\\"\]
                case 34:
                    return q2();
                // \[,\]
                case 44:
                    return q9();
                // \[\\-\]
                case
    
    The Lounge
  • Login

  • Don't have an account? Register

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