mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 01:54:01 +02:00
Fix slow unsized number parsing (#5577)
Try to avoid allocating and deallocating a full --max-num-width buffer on parsing every single unsized number literal.
This commit is contained in:
+6
-1
@@ -198,7 +198,12 @@ void V3Number::create(const char* sourcep) {
|
||||
}
|
||||
// Otherwise...
|
||||
else if (!sized()) {
|
||||
width(v3Global.opt.maxNumWidth(), false); // Will change width below
|
||||
// We don't use v3Global.opt.maxNumWidth() here, as it can be arbitrarily large,
|
||||
// and cause extremely slow parsing. We will resize the value at the end anyway.
|
||||
// We just need a width big enough to fit the constant, so we use a conservative
|
||||
// upper bound to start from. Should never need more than 4 bits per digit.
|
||||
const int widthBound = std::max<int>(32, std::strlen(value_startp) * 4);
|
||||
width(widthBound, false); // Will change width below
|
||||
if (unbased) isSigned(true); // Also says the spec.
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user