3 ms·
I have been grepping through the tree trying to find the implementation of the String class. A part of me thinks they just defined it in string.js and somehow m
by yan 18y ago
I have been grepping through the tree trying to find the implementation of the String class. A part of me thinks they just defined it in string.js and somehow made the rest of the code treat it as a cpp class.
- jlouis 18y agoit is not uncommon to patch primitives into your language by having special "__primitive" or something such annotations which can be added to call over a language barrier. In this case, you would annotate certain Javascript functions/classes so they refer to their C++ equivalent code. You gain the advantage that the difference between library code and primitive built-in things blur more so one function can be implemented as a javascript function (because the compiler already produces good code for that part), while another function (un-implementable in JS) is C++.
- shadytrees 18y agoI think (fuzzily), from what I can find, that string-stream.cc allocates a block of char's for a string. Once the string grows beyond the capacity, `char* HeapStringAllocator::grow(unsigned* bytes)` doubles the size of the allocated buffer. Kind of disappointing after half an hour of reading and C-s'ing in Emacs. `string.js` is used by `tools/js2c.py` to create a `string.h`, but otherwise I think many of the string functions are implemented in JavaScript and (I'm guessing) compiled later since `string.js` and other JavaScript files are referencing C macros.