Recent

Author Topic: [CLOSED] Question about the internal structure of FpJSON  (Read 495 times)

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 451
  • I use FPC [main] 💪🐯💪
[CLOSED] Question about the internal structure of FpJSON
« on: August 11, 2025, 07:33:12 pm »
I am trying to understand why JSONScanner.pp in TJSONScanner has an FParts array in which the start and length of the token are encoded each time, then decoding and token construction in the form of a string is performed.

Why is this intermediate encoding-decoding necessary? I tried to understand, figure it out, find an example, but I couldn't.

After several tests, I get the impression that this array is never filled with more than one token... then what is it for?

Also, after testing, I see that all strings were created (initially, I thought that this array somehow cleverly allowed strings not to be created if they were not needed, but according to the test results, all strings are created).

Thus, at the moment, this array only slows down the parser's work without providing any advantage — it is easier to build a string right away.

BUT, maybe I'm missing something, and someone can explain to me how it works in more detail?


https://gitlab.com/freepascal.org/fpc/source/-/blob/5101d2c4ac68ddbb1872eecb096be852597792c2/packages/fcl-json/src/jsonscanner.pp#L86
https://gitlab.com/freepascal.org/fpc/source/-/blob/5101d2c4ac68ddbb1872eecb096be852597792c2/packages/fcl-json/src/jsonscanner.pp#L366
https://gitlab.com/freepascal.org/fpc/source/-/blob/5101d2c4ac68ddbb1872eecb096be852597792c2/packages/fcl-json/src/jsonscanner.pp#L390
« Last Edit: August 12, 2025, 08:55:39 am by ALLIGATOR »
I may seem rude - please don't take it personally

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 451
  • I use FPC [main] 💪🐯💪
Re: Question about the internal structure of FpJSON
« Reply #1 on: August 12, 2025, 08:55:06 am »
In the morning, with a fresh head and more detailed testing, I understood why it was necessary
I may seem rude - please don't take it personally

 

TinyPortal © 2005-2018