Show HN: SuperString – A fast and memory-optimized string library for C++
github.com
github.com
Some high level things you may want to learn: the "mutable" keyword (to stop having to cast "this", "const_cast" (when you actually do need to cast "this"), "enum" (so that you don't have to use "Bool" in the way you do), smart pointers (reference counting is hard, you should let the compiler take care of it for you in this case), "delete []" (make sure to always pair it with "new []").
I also do not believe the benchmarks to be meaningful.
And here is a summary of the warnings I get when compiling with "-Weverything":
26 [-Wcast-align]
20 [-Wcast-qual]
6 [-Wconditional-uninitialized]
24 [-Wdollar-in-identifier-extension]
172 [-Wold-style-cast]
2 [-Wshorten-64-to-32]
3 [-Wsign-compare]
25 [-Wsign-conversion]
3 [-Wunused-parameter]
72 [-Wzero-as-null-pointer-constant]
Please don't use this code.To the OP: you should use theses tests to validate your implementation https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt (caveat: 5- and 6-byte sequences are no longer valid UTF-8 and should be rejected).
With 2280 lines, a unit test or two would make me way less apprehensive.
If this is not obvious to you, start to think about the numbers in the benchmark, and remember it's really friggin easy to do silly errors in C++ with massive consequences on runtime and resource consumption. So, in real life, if you do something utilizing the basic library and the numbers are way off, debug, re-read the code, benchmark. Step through the code in the debugger. Litter it with printfs and so on. If a novice, read through stackoverflow and other resources, and go through the manual pages of the suggested implementation, and understand what is going on under the hood (try to translate the solution into C in your head).
Anything but careening away to create your own custom library.
Comments in this thread provided several explicit things wrong with this already.
Here's a video from explaining the motivation behind the project (https://www.youtube.com/watch?v=kPR8h4-qZdk).
Nothing wrong with writing something and sharing it in order to learn, though! Just surprised to see it on the front page.
+// in case NULL is not defined
+#ifndef NULL
+#define NULL (0L)
+#endif // NULL
https://github.com/btwael/SuperString/commit/515f6896ee6a3e2... return this->_lengthComputed == ((Bool) 2);
Obviously so that you can add a third value :) :)https://github.com/btwael/SuperString/blob/master/test/withS... this line should be ` lines.push_back(string.substr(last, i - last));` (it also drops the very last line, but who's counting, eh?).
If the 210kb file has a line every 80 bytes or so and is copied this way, it works out to around 490MB of data (caveat: my math may be wrong).
for(Size i = 0; i < this->_memoryLength; i++) {
*(this->_data + i) = *(sequence->_bytes + i);
}
I'd rather use std::memcpy.[1]: https://github.com/Microsoft/referencesource/blob/master/msc...
edit: link to the talk: https://www.youtube.com/watch?v=7GTpwgsmHgU
(*remarkable, not remarquable by the way)