Cramming is not useless, it is short-lived
The spacing literature is often summarised as showing that cramming does not work, which is not quite what it shows. Massed practice produces good performance on an immediate test — sometimes better than spaced practice does at very short delays. What it fails to produce is retention. Cepeda and colleagues found the advantage of spacing growing with the delay before testing, which means the two techniques are answering different questions. If the only thing standing between you and the material is tomorrow morning, cramming addresses that. If you need the material for a cumulative final, or for the job the qualification is for, it does not.
How to cram better than you would by default
The default cram is rereading notes until they feel familiar, which is close to the least effective use of the hours. Test yourself instead: close the notes and write down what you remember, work problems without the worked solution beside you, answer practice questions and check them. Roediger and Karpicke found retrieval beating restudy even at short delays in some conditions, and it dominates at any delay longer than a few minutes. Cover the material in more than one pass rather than one slow careful pass, and put a short break between passes even if the break is only an hour — that is spacing at the only scale available to you.
What to do about the next exam
The honest thing to say about the sleep question is that the evidence on trading sleep for study hours is not strong enough to give you a rule, but the study on cognitive performance after restricted sleep is consistent enough that an all-nighter before a morning exam is a poor trade for most people. After the exam is over, the useful move is a schedule rather than a resolution. Cramming happens because the decision about when to study was never made, not because anyone chose it on the merits. The Study Schedule Planner exists to make that decision once, at a moment when you are not under pressure.